如何在 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中的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 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 27,129 | Version: 2025.11 刚刚发布