如何在 C# 中為文字加入光暈效果

如何在 C# 中為文字添加發光效果

This article was translated from English: Does it need improvement?
Translated
View the article in English

文字發光效果是一種視覺效果,它會在字元周圍產生發光的光環。 這種效果使文字看起來像是在發光,形成柔和、發光的輪廓,可以增強可讀性並吸引註意力。

快速入門:快速為文字元素套用發光效果

只需實例化一個發光對象,設定其半徑和顏色,將其嵌入到文字效果中,並將其分配給文字樣式即可。 短短一行字,你就能在 Word 文件中看到發光的文字。

Nuget Icon立即開始使用 NuGet 建立 PDF 檔案:

  1. 使用 NuGet 套件管理器安裝 IronWord

    PM > Install-Package IronWord

  2. 複製並運行這段程式碼。

    someTextElement.Style.TextEffect = new IronWord.Models.TextEffect { GlowEffect = new IronWord.Models.Glow { GlowRadius = 8, GlowColor = System.Drawing.Color.FromArgb(180, 0, 128, 255) } };
  3. 部署到您的生產環境進行測試

    立即開始在您的專案中使用 IronWord,免費試用!
    arrow pointer

IronWord入門

立即開始在您的項目中使用 IronWord 並免費試用。

第一步:
green arrow pointer

添加發光效果

若要為文字指定發光效果,可以先建立並配置發光物件。 然後,從這個發光物件創建文字效果物件。 最後,將 TextEffect 賦值給文字的TextEffect屬性。

using IronWord; // Import the necessary library

public class TextGlowEffectExample
{
    public void ApplyGlowEffect()
    {
        // Initialize a new Glow object
        Glow glow = new Glow();

        // Set the properties for the glow effect
        glow.GlowRadius = 5; // Radius of the glow effect
        glow.GlowColor = System.Drawing.Color.FromArgb(128, 255, 0, 0); // ARGB value for the glow color

        // Create a TextEffect object and assign the glow effect to it
        TextEffect textEffect = new TextEffect();
        textEffect.Glow = glow;

        // Apply the TextEffect to the text
        // Example: someTextElement.TextEffect = textEffect;

        // Further code to export or display the document would go here
    }
}
using IronWord; // Import the necessary library

public class TextGlowEffectExample
{
    public void ApplyGlowEffect()
    {
        // Initialize a new Glow object
        Glow glow = new Glow();

        // Set the properties for the glow effect
        glow.GlowRadius = 5; // Radius of the glow effect
        glow.GlowColor = System.Drawing.Color.FromArgb(128, 255, 0, 0); // ARGB value for the glow color

        // Create a TextEffect object and assign the glow effect to it
        TextEffect textEffect = new TextEffect();
        textEffect.Glow = glow;

        // Apply the TextEffect to the text
        // Example: someTextElement.TextEffect = textEffect;

        // Further code to export or display the document would go here
    }
}
Imports IronWord ' Import the necessary library

Public Class TextGlowEffectExample
	Public Sub ApplyGlowEffect()
		' Initialize a new Glow object
		Dim glow As New Glow()

		' Set the properties for the glow effect
		glow.GlowRadius = 5 ' Radius of the glow effect
		glow.GlowColor = System.Drawing.Color.FromArgb(128, 255, 0, 0) ' ARGB value for the glow color

		' Create a TextEffect object and assign the glow effect to it
		Dim textEffect As New TextEffect()
		textEffect.Glow = glow

		' Apply the TextEffect to the text
		' Example: someTextElement.TextEffect = textEffect;

		' Further code to export or display the document would go here
	End Sub
End Class
$vbLabelText   $csharpLabel
添加發光效果

發光效果特性

以下是所有發光效果屬性及其說明:

  • GlowRadius :取得或設定發光效果的半徑。 發光半徑以點(1/72 英吋)為單位指定。
  • GlowColor :取得或設定發光效果的顏色。

發光效果範例

我們來看一些發光效果的例子。 發光效果的顏色也可以接受 ARGB 值。 第一個值是 alpha 值,它描述顏色的不透明度。

發光效果範例

常見問題解答

如何為 Word 文件中的文字加入螢光效果?

若要為 Word 文件中的文字加入螢光效果,請使用專為此目的設計的 C# 函式庫。初始化一個 Glow 物件,設定它的屬性,例如 GlowRadiusGlowColor 並將它指定給一個 TextEffect 物件。最後,套用此 TextEffect 到您的文字並匯出文件。

使用 C# 為文字套用螢光效果需要哪些程式碼?

您可以透過匯入必要的函式庫,並建立一個具有所需屬性的 Glow 物件,來套用螢光效果。將此物件指定給 TextEffect 物件,並套用至您的文字。

文字編輯中的螢光效果有哪些主要特性?

炫光效果的關鍵屬性為 GlowRadius (以點為單位設定炫光的半徑) 和 GlowColor (定義炫光的顏色)。這些屬性可以用來自訂炫光效果的外觀。

是否可以使用 ARGB 值自訂螢光顏色?

是的,炫光顏色可以使用 ARGB 值自訂。ARGB 中的α值決定了光彩的不透明度,允許大範圍的顏色自訂。

套用炫光效果後,如何匯出 Word 文件?

使用 C# 函式庫套用螢光效果後,透過呼叫函式庫提供的適當方法匯出已編輯的 Word 文件,將文件儲存或顯示為新檔案。

是否可以在新文字和現有文字上都套用螢光效果?

是的,您可以將炫光效果套用至 Word 文件中新建立和現有的文字。這種靈活性可讓您增強文件中的任何文字元素。

GlowRadius 屬性的目的是什麼?

GlowRadius 屬性指定以點為單位的炫光效果半徑,有助於確定炫光從文字延伸多遠。半徑以點為單位,1 點等於 1/72 英吋。

在 C# 中配置螢光效果需要哪些步驟?

要在 C# 中配置輝光效果,請初始化 Glow 物件,設定其 GlowRadiusGlowColor 屬性,並將其指定給 TextEffect 物件。將 TextEffect 套用至您的文字,並匯出文件以查看變更。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 27,129 | Version: 2025.11 剛發表