How to Add Glow Effect to Text in C
發光效果會在文字字元周圍產生一圈光暈。 此視覺效果使文字呈現出散發光芒並帶有柔和輪廓的效果。在 C# 應用程式中,特別是 WORD 文件,發光效果有助於突顯標題、副標題及重要內容。 此效果廣泛應用於簡報、行銷資料及Professional文件中,用於需要視覺強調的文字。
快速入門:快速為文字元素套用發光效果
建立一個 Glow 物件,設定其 GlowRadius 和 GlowColor,將其嵌入 TextEffect 中,並將其指派給您的文字樣式。 只需一行代碼,即可在您的 WORD 文件中生成發光文字。
-
using NuGet 套件管理員安裝 https://www.nuget.org/packages/IronWord
PM > Install-Package IronWord -
請複製並執行此程式碼片段。
using IronWord; using IronWord.Models; WordDocument doc = new WordDocument(); TextStyle textStyle = new TextStyle(); textStyle.TextEffect = new TextEffect() { GlowEffect = new Glow() { GlowColor = IronWord.Models.Co/lor.Aqua, GlowRadius = 10 } }; Paragraph paragraph = new Paragraph(); Run textRun = new Run(new TextContent("Glowing Text")); textRun.Style = textStyle; paragraph.AddChild(textRun); doc.AddParagraph(paragraph); doc.SaveAs("glow.docx"); -
部署至您的生產環境進行測試
立即透過免費試用,在您的專案中開始使用 IronWord
如何為文字添加光暈效果(5 個步驟)
- 安裝 IronWord:
Install-Package IronWord - 建立一個
TextStyle並設定GlowEffect並使用GlowColor並GlowRadius - 建立一個
Run包含TextContent並將TextStyle至Run - 請將
Run至ParagraphusingAddChild - 儲存文件
如何在 C# 中為文字添加發光效果?
若要套用發光效果,請建立 TextStyle,並將其 TextEffect 屬性填入 GlowEffect。 接著建立一個 Paragraph,其後接一個包含 TextContent 的 Run。 將 TextStyle 指派給 Run(而非 TextContent),然後使用 AddChild 將 Run 加入 Paragraph 中。 此文件遵循以下層級結構:Document → Paragraph → Run → TextContent。 此方法可讓您完全掌控光暈的外觀與強度。
為何先建立 Glow 物件如此重要?
先建立一個 Glow 物件,即可在套用前設定所有發光屬性。 這遵循了關注點分離原則,並提升了程式碼的可維護性。 獨立定義發光屬性,可讓其於多個文字元素間重複使用,並能根據應用程式需求進行動態調整。 此模式與其他 Iron Software產品處理類似效果的方式相符,以確保文件處理工作流程的一致性。
using IronWord;
using IronWord.Models;
using System.Drawing;
public class TextGlowEffectExample
{
public void ApplyGlowEffect()
{
// Create a new Word document
WordDocument doc = new WordDocument();
// Add a paragraph with text
Paragraph paragraph = new Paragraph();
Text textRun = new Text("This text has a bright glow!");
paragraph.AddTextRun(textRun);
// Initialize a new Glow object
Glow glow = new Glow();
// Set the properties for the glow effect
glow.GlowRadius = 15; // Radius of the glow effect in points
glow.GlowColor = Color.FromArgb(200, 0, 255, 255); // Semi-transparent cyan
// Create a TextEffect object and assign the glow effect to it
TextEffect textEffect = new TextEffect();
textEffect.GlowEffect = glow;
// Apply the TextEffect to the text
textRun.Style = new TextStyle();
textRun.Style.TextEffect = textEffect;
// Add the paragraph to the document
doc.AddParagraph(paragraph);
// 儲存文件
doc.SaveAs("glowing-text-example.docx");
}
}
using IronWord;
using IronWord.Models;
using System.Drawing;
public class TextGlowEffectExample
{
public void ApplyGlowEffect()
{
// Create a new Word document
WordDocument doc = new WordDocument();
// Add a paragraph with text
Paragraph paragraph = new Paragraph();
Text textRun = new Text("This text has a bright glow!");
paragraph.AddTextRun(textRun);
// Initialize a new Glow object
Glow glow = new Glow();
// Set the properties for the glow effect
glow.GlowRadius = 15; // Radius of the glow effect in points
glow.GlowColor = Color.FromArgb(200, 0, 255, 255); // Semi-transparent cyan
// Create a TextEffect object and assign the glow effect to it
TextEffect textEffect = new TextEffect();
textEffect.GlowEffect = glow;
// Apply the TextEffect to the text
textRun.Style = new TextStyle();
textRun.Style.TextEffect = textEffect;
// Add the paragraph to the document
doc.AddParagraph(paragraph);
// 儲存文件
doc.SaveAs("glowing-text-example.docx");
}
}
Imports IronWord
Imports IronWord.Models
Imports System.Drawing
Public Class TextGlowEffectExample
Public Sub ApplyGlowEffect()
' Create a new Word document
Dim doc As New WordDocument()
' Add a paragraph with text
Dim paragraph As New Paragraph()
Dim textRun As New Text("This text has a bright glow!")
paragraph.AddTextRun(textRun)
' Initialize a new Glow object
Dim glow As New Glow()
' Set the properties for the glow effect
glow.GlowRadius = 15 ' Radius of the glow effect in points
glow.GlowColor = Color.FromArgb(200, 0, 255, 255) ' Semi-transparent cyan
' Create a TextEffect object and assign the glow effect to it
Dim textEffect As New TextEffect()
textEffect.GlowEffect = glow
' Apply the TextEffect to the text
textRun.Style = New TextStyle()
textRun.Style.TextEffect = textEffect
' Add the paragraph to the document
doc.AddParagraph(paragraph)
' Save the document
doc.SaveAs("glowing-text-example.docx")
End Sub
End Class
什麼是發光效果屬性?
理解發光效果的屬性對於創建Professional級效果至關重要,這些效果能提升文件質感,同時不至於壓過內容本身。 適當的授權可確保這些功能在生產環境中不受限制地運作。
哪些屬性會控制發光效果的外觀?
-
GlowRadius:以點(1/72 英吋)為單位設定光暈效果的半徑。 數值通常介於 5 至 30 分之間。 數值越大,光暈效果越發朦朧且擴散。 半徑 5 至 10 點可產生細微的高亮效果; 20-30 點可產生戲劇性的光暈效果。 GlowColor:設定發光效果的顏色。 支援System.Drawing.Co/lor值,包含用於控制透明度的 ARGB 格式。 鮮豔的色彩(青色、黃色、洋紅色)能營造出生動的效果; 較深的顏色用於提供微妙的強調效果。
如何設定帶有 Alpha 透明度的色彩值?
Alpha 透明度可創造逼真的光暈效果,與背景自然融合。 Alpha 值範圍為 0(透明)至 255(不透明)。 以下是一個展示不同 alpha 值的範例:
using IronWord;
using IronWord.Models;
using System.Drawing;
public class AlphaTransparencyExample
{
public void DemonstrateAlphaValues()
{
WordDocument doc = new WordDocument();
// Create multiple text samples with different alpha values
int[] alphaValues = { 50, 100, 150, 200, 255 };
foreach (int alpha in alphaValues)
{
Paragraph para = new Paragraph();
Text text = new Text($"Alpha: {alpha} - Glow Effect Sample");
// Create glow with specific alpha transparency
Glow glow = new Glow
{
GlowRadius = 12,
GlowColor = Color.FromArgb(alpha, 255, 215, 0) // Gold with varying transparency
};
// Apply the glow effect
TextEffect effect = new TextEffect { GlowEffect = glow };
text.Style = new TextStyle
{
TextEffect = effect,
FontSize = 24,
FontFamily = "Arial"
};
para.AddTextRun(text);
doc.AddParagraph(para);
}
doc.SaveAs("alpha-transparency-demo.docx");
}
}
using IronWord;
using IronWord.Models;
using System.Drawing;
public class AlphaTransparencyExample
{
public void DemonstrateAlphaValues()
{
WordDocument doc = new WordDocument();
// Create multiple text samples with different alpha values
int[] alphaValues = { 50, 100, 150, 200, 255 };
foreach (int alpha in alphaValues)
{
Paragraph para = new Paragraph();
Text text = new Text($"Alpha: {alpha} - Glow Effect Sample");
// Create glow with specific alpha transparency
Glow glow = new Glow
{
GlowRadius = 12,
GlowColor = Color.FromArgb(alpha, 255, 215, 0) // Gold with varying transparency
};
// Apply the glow effect
TextEffect effect = new TextEffect { GlowEffect = glow };
text.Style = new TextStyle
{
TextEffect = effect,
FontSize = 24,
FontFamily = "Arial"
};
para.AddTextRun(text);
doc.AddParagraph(para);
}
doc.SaveAs("alpha-transparency-demo.docx");
}
}
Imports IronWord
Imports IronWord.Models
Imports System.Drawing
Public Class AlphaTransparencyExample
Public Sub DemonstrateAlphaValues()
Dim doc As New WordDocument()
' Create multiple text samples with different alpha values
Dim alphaValues As Integer() = {50, 100, 150, 200, 255}
For Each alpha As Integer In alphaValues
Dim para As New Paragraph()
Dim text As New Text($"Alpha: {alpha} - Glow Effect Sample")
' Create glow with specific alpha transparency
Dim glow As New Glow With {
.GlowRadius = 12,
.GlowColor = Color.FromArgb(alpha, 255, 215, 0) ' Gold with varying transparency
}
' Apply the glow effect
Dim effect As New TextEffect With {.GlowEffect = glow}
text.Style = New TextStyle With {
.TextEffect = effect,
.FontSize = 24,
.FontFamily = "Arial"
}
para.AddTextRun(text)
doc.AddParagraph(para)
Next
doc.SaveAs("alpha-transparency-demo.docx")
End Sub
End Class
Alpha 值指南:
- 50-100:極為細微、幾乎不可見的水印式效果
- 100-150:柔和光暈,適合商務文件的專業外觀
- 150-200 字:中等篇幅,標題與正文篇幅均衡
- 200-255: 強烈的光澤感,適合用於宣傳材料
有哪些發光效果的範例?
光暈效果支援 ARGB 色彩值。 alpha 值用於控制透明度。 這些範例展示了 Glow 在各種文件情境中的實際應用。 在正式部署前,請先設定正確的授權金鑰。
何時應使用不同的半徑值?
不同的半徑值適用於不同的用途。 使用小半徑(5-10 點)的光暈效果,可對術語或連結進行精準的視覺強調。 章節標題與標題建議使用中等字號(15-20 點),以建立清晰的層級結構。 大字號(25 點以上)適合用於封面頁或需要最大視覺衝擊力的宣傳標語。
以下為展示半徑應用的實作範例:
public class RadiusExamples
{
public void CreateRadiusComparison()
{
WordDocument doc = new WordDocument();
// Example 1: Subtle emphasis for inline text
Paragraph p1 = new Paragraph();
Text subtleText = new Text("Important: This deadline cannot be extended.");
subtleText.Style = new TextStyle
{
TextEffect = new TextEffect
{
GlowEffect = new Glow
{
GlowRadius = 6,
GlowColor = Color.FromArgb(180, 255, 0, 0) // Soft red glow
}
}
};
p1.AddTextRun(subtleText);
// Example 2: Section header with medium glow
Paragraph p2 = new Paragraph();
Text headerText = new Text("Chapter 1: Getting Started");
headerText.Style = new TextStyle
{
FontSize = 28,
FontFamily = "Calibri",
TextEffect = new TextEffect
{
GlowEffect = new Glow
{
GlowRadius = 18,
GlowColor = Color.FromArgb(150, 0, 120, 215) // Corporate blue
}
}
};
p2.AddTextRun(headerText);
// Example 3: Promotional text with large glow
Paragraph p3 = new Paragraph();
Text promoText = new Text("SPECIAL OFFER - LIMITED TIME!");
promoText.Style = new TextStyle
{
FontSize = 36,
Bold = true,
TextEffect = new TextEffect
{
GlowEffect = new Glow
{
GlowRadius = 30,
GlowColor = Color.FromArgb(220, 255, 255, 0) // Bright yellow
}
}
};
p3.AddTextRun(promoText);
doc.AddParagraph(p1);
doc.AddParagraph(p2);
doc.AddParagraph(p3);
doc.SaveAs("radius-examples.docx");
}
}
public class RadiusExamples
{
public void CreateRadiusComparison()
{
WordDocument doc = new WordDocument();
// Example 1: Subtle emphasis for inline text
Paragraph p1 = new Paragraph();
Text subtleText = new Text("Important: This deadline cannot be extended.");
subtleText.Style = new TextStyle
{
TextEffect = new TextEffect
{
GlowEffect = new Glow
{
GlowRadius = 6,
GlowColor = Color.FromArgb(180, 255, 0, 0) // Soft red glow
}
}
};
p1.AddTextRun(subtleText);
// Example 2: Section header with medium glow
Paragraph p2 = new Paragraph();
Text headerText = new Text("Chapter 1: Getting Started");
headerText.Style = new TextStyle
{
FontSize = 28,
FontFamily = "Calibri",
TextEffect = new TextEffect
{
GlowEffect = new Glow
{
GlowRadius = 18,
GlowColor = Color.FromArgb(150, 0, 120, 215) // Corporate blue
}
}
};
p2.AddTextRun(headerText);
// Example 3: Promotional text with large glow
Paragraph p3 = new Paragraph();
Text promoText = new Text("SPECIAL OFFER - LIMITED TIME!");
promoText.Style = new TextStyle
{
FontSize = 36,
Bold = true,
TextEffect = new TextEffect
{
GlowEffect = new Glow
{
GlowRadius = 30,
GlowColor = Color.FromArgb(220, 255, 255, 0) // Bright yellow
}
}
};
p3.AddTextRun(promoText);
doc.AddParagraph(p1);
doc.AddParagraph(p2);
doc.AddParagraph(p3);
doc.SaveAs("radius-examples.docx");
}
}
Public Class RadiusExamples
Public Sub CreateRadiusComparison()
Dim doc As New WordDocument()
' Example 1: Subtle emphasis for inline text
Dim p1 As New Paragraph()
Dim subtleText As New Text("Important: This deadline cannot be extended.")
subtleText.Style = New TextStyle With {
.TextEffect = New TextEffect With {
.GlowEffect = New Glow With {
.GlowRadius = 6,
.GlowColor = Color.FromArgb(180, 255, 0, 0) ' Soft red glow
}
}
}
p1.AddTextRun(subtleText)
' Example 2: Section header with medium glow
Dim p2 As New Paragraph()
Dim headerText As New Text("Chapter 1: Getting Started")
headerText.Style = New TextStyle With {
.FontSize = 28,
.FontFamily = "Calibri",
.TextEffect = New TextEffect With {
.GlowEffect = New Glow With {
.GlowRadius = 18,
.GlowColor = Color.FromArgb(150, 0, 120, 215) ' Corporate blue
}
}
}
p2.AddTextRun(headerText)
' Example 3: Promotional text with large glow
Dim p3 As New Paragraph()
Dim promoText As New Text("SPECIAL OFFER - LIMITED TIME!")
promoText.Style = New TextStyle With {
.FontSize = 36,
.Bold = True,
.TextEffect = New TextEffect With {
.GlowEffect = New Glow With {
.GlowRadius = 30,
.GlowColor = Color.FromArgb(220, 255, 255, 0) ' Bright yellow
}
}
}
p3.AddTextRun(promoText)
doc.AddParagraph(p1)
doc.AddParagraph(p2)
doc.AddParagraph(p3)
doc.SaveAs("radius-examples.docx")
End Sub
End Class
發光效果的常見配色組合有哪些?
有效的配色組合取決於文件目的與品牌形象。 Professional文件通常採用淡藍色、灰色或品牌色,並搭配較低的透明度值。 行銷素材採用鮮明的互補色或高對比色組合。 若同時使用多款 Iron Software產品,請查閱產品更新以確認相容性。
常見的配色組合:
- Professional藍:深藍色文字搭配淺藍色光暈(RGB:100, 150, 255)
- 溫暖強調:深棕色文字搭配金色光暈(RGB:255, 200, 50)
- 高對比度:黑色文字搭配白色/銀色光暈(RGB:220, 220, 220)
- 品牌色彩:公司色文字搭配互補色光暈
- 季節性主題:節日採用綠色/紅色,萬聖節採用橘色/黑色
亮光效果應提升可讀性,而非造成干擾。 請在不同背景上測試組合效果,並遵循無障礙指南。 若Enterprise應用程式需要延伸支援,請探索授權擴充方案,以持續獲得更新與新功能。 在擴展應用程式時,升級選項能為日益壯大的團隊及不斷擴增的需求提供靈活性。
常見問題
如何使用 C# 在 WORD 文件中為文字添加發光效果?
若要使用 IronWord 添加發光效果,請建立一個具有所需半徑和顏色設定的 Glow 物件,然後將其嵌入 TextEffect 物件中,並將其指派給文字元素的 Style.TextEffect 屬性。 此操作可透過以下單行程式碼完成:someTextElement.Style.TextEffect = new IronWord.Models.TextEffect { GlowEffect = new IronWord.Models.Glow { GlowRadius = 8, GlowColor = System.Drawing.Co/lor.FromArgb(180, 0, 128, 255) } };
要製作發光文字,至少需要哪些程式碼?
IronWord 讓您只需一行程式碼即可建立發光文字,方法是將文字元件的 Style.TextEffect 屬性設定為一個包含已配置 Glow 物件的新 TextEffect。這包含在單一陳述式中設定發光半徑與顏色。
我可以自訂光暈效果的外觀嗎?
是的,IronWord 透過 Glow 物件的屬性提供完整的發光效果自訂功能。您可以調整 GlowRadius(單位為點)來控制發光大小,並使用 System.Drawing.Co/lor 搭配 ARGB 值設定 GlowColor,以精確控制顏色與透明度。
為何要建立獨立的 Glow 物件,而非採用內嵌式設定?
在 IronWord 中建立獨立的 Glow 物件,既遵循了關注點分離原則,也提升了程式碼的可維護性。此方法讓您能在多個文字元素間重複使用相同的 Glow 設定,並根據應用程式需求動態修改屬性,這與 Iron Software產品中採用的一致模式相符。
為文字套用發光效果的主要步驟有哪些?
IronWord 的工作流程包含 5 個步驟:1) 下載 IronWord C# 程式庫,2) 將文字效果套用至新建立或現有的文字,3) 設定 Glow 物件的半徑與顏色,4) 將 Glow 指派給 TextEffect 物件的 GlowEffect 屬性,5) 將編輯後的 WORD 文件匯出為新檔案。
哪些類型的文件適合使用文字發光效果?
IronWord 的光暈效果功能對於製作簡報、行銷素材及需要視覺強調文字的 Professional 文件特別有用。這種發光光暈效果有助於在 WORD 文件中突顯標題、副標題及重要內容。

