如何在 C# 中給文本添加光暈效果

How to Add Glow Effect to Text

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

The glow effect on text is a visual effect that creates a glowing aura around the characters. This effect makes the text appear as if it is emitting light, creating a soft, luminous outline that can enhance readability and draw attention.

Quickstart: Apply Glow Effect to a Text Element Fast

Just instantiate a Glow object, set its radius and color, embed it in a TextEffect, and assign it to your text’s style. In one short line you’ll see glowing text in your Word document.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronWord with NuGet Package Manager

    PM > Install-Package IronWord

  2. Copy and run this code snippet.

    someTextElement.Style.TextEffect = new IronWord.Models.TextEffect { GlowEffect = new IronWord.Models.Glow { GlowRadius = 8, GlowColor = System.Drawing.Color.FromArgb(180, 0, 128, 255) } };
  3. Deploy to test on your live environment

    Start using IronWord in your project today with a free trial
    arrow pointer

Get Started with IronWord

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

第一步:
green arrow pointer

Add Glow Effect

To specify the glow effect for the text, you can start by creating and configuring the Glow object. Then, create the TextEffect object from this Glow object. Finally, assign the TextEffect to the TextEffect property of the text.

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
Add glow effect

Glow Effect Properties

Below are all the glow effect properties and their descriptions:

  • GlowRadius: Gets or sets the radius of the glow effect. The glow radius is specified in points (1/72 inch).
  • GlowColor: Gets or sets the color of the glow effect.

Glow Effect Examples

Let's look at some more glow effect examples. The color of the glow effect can also accept ARGB values. The first value is alpha, which describes how opaque the color is.

Glow effect examples

常見問題解答

如何在 Word 文件中為文字添加光暈效果?

要在 Word 文件中給文字添加光暈效果,請使用為此目的設計的 C# 庫。初始化 Glow 對象,配置其屬性如 GlowRadiusGlowColor,並將其分配給 TextEffect 對象。最後,將此 TextEffect 應用於您的文字並導出文件。

要使用 C# 為文字應用光暈效果需要什麼代碼?

您可以通過導入所需的庫並創建具有所需屬性的 Glow 對象來應用光暈效果。將其分配給 TextEffect 對象並應用於您的文字。

文字編輯中光暈效果的關鍵屬性是什麼?

光暈效果的關鍵屬性是 GlowRadius,它設置光暈的半徑(以點為單位),以及 GlowColor,它定義光暈的顏色。可以配置這些屬性以自定義光暈效果的外觀。

可以使用 ARGB 值自定義光暈顏色嗎?

是的,可以使用 ARGB 值自定義光暈顏色。ARGB 中的 alpha 值決定了光暈的不透明度,允許廣泛的顏色自定義。

應用光暈效果後如何導出 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 下載 25,807 | 版本: 2025.11 剛剛發布