如何在 C# 中為文字新增倒影效果
使用 IronWord 的 API,即可在 C# 中為文字套用鏡面倒影效果。只需一行程式碼,就能模擬文字映在表面上的倒影,增加視覺深度。
快速入門:在 C# 中對文字套用倒影效果使用 IronWord,只需一行程式碼就能為任何文字套用預設倒影效果,無須繁複的設定或樣板程式碼。
-
1使用 IronWord 安裝 NuGet Package Manager
-
2複製並運行這段程式碼。
using IronWord; using IronWord.Models; WordDocument doc = new WordDocument(); TextStyle textStyle = new TextStyle(); textStyle.TextEffect = new TextEffect() { ReflectionEffect = new Reflection() }; Paragraph paragraph = new Paragraph(); Run textRun = new Run(new TextContent("Reflection Text")); textRun.Style = textStyle; paragraph.AddChild(textRun); doc.AddParagraph(paragraph); doc.SaveAs("reflection.docx");Imports IronWord Imports IronWord.Models Dim doc As New WordDocument() Dim textStyle As New TextStyle() textStyle.TextEffect = New TextEffect() With {.ReflectionEffect = New Reflection()} Dim paragraph As New Paragraph() Dim textRun As New Run(New TextContent("Reflection Text")) textRun.Style = textStyle paragraph.AddChild(textRun) doc.AddParagraph(paragraph) doc.SaveAs("reflection.docx")Imports IronWord Imports IronWord.Models Dim doc As New WordDocument() Dim textStyle As New TextStyle() textStyle.TextEffect = New TextEffect() With {.ReflectionEffect = New Reflection()} Dim paragraph As New Paragraph() Dim textRun As New Run(New TextContent("Reflection Text")) textRun.Style = textStyle paragraph.AddChild(textRun) doc.AddParagraph(paragraph) doc.SaveAs("reflection.docx") -
3部署到您的生產環境進行測試
立即在您的項目中開始使用 IronWord,並使用 免費試用
如何為文字新增倒影效果(5 個步驟)
- 安裝 IronWord:
Install-Package IronWord - 建立
TextStyle並使用new Reflection()來設定ReflectionEffect - 建立一個包含
TextContent的Run,並將TextStyle指派給該Run - 使用
AddChild將Run加入Paragraph - 儲存文件
如何新增倒影效果?
要套用倒影效果,請建立 TextStyle,在其 TextEffect 屬性中設定 ReflectionEffect。接著建立 Paragraph 和包含 TextContent 的 Run。將 TextStyle 指派給 Run(而非 TextContent),再使用 AddChild 將 Run 加入 Paragraph。文件的階層結構為 Document → Paragraph → Run → TextContent。
倒影效果可為重要文字增添層次和視覺變化,適合用在專業文件的標頭、標題或關鍵資訊。這種效果模擬文字映在光滑表面上的樣子,營造簡潔、現代的外觀,吸引讀者注意。
為什麼建立TextStyle很重要?
IronWord 使用 TextStyle 物件集中管理文字格式。將樣式與內容分開後,多個文字元素可共用相同的倒影效果,讓整份文件維持一致。只要修改同一個樣式物件,就能一次更新所有套用該樣式的倒影。
using IronWord;
using IronWord.Models;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ReflectionEffect = new Reflection(),
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("reflectionEffect.docx");using IronWord;
using IronWord.Models;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ReflectionEffect = new Reflection(),
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("reflectionEffect.docx");Imports IronWord
Imports IronWord.Models
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ReflectionEffect = New Reflection()
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("reflectionEffect.docx")Imports IronWord
Imports IronWord.Models
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ReflectionEffect = New Reflection()
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("reflectionEffect.docx")預設倒影效果看起來如何?
預設效果會在文字下方呈現淡淡的鏡像,並讓倒影的透明度逐漸增加。這項預設適用於多數商務文件和簡報,無須另外設定。倒影與文字保持固定距離,模糊度與透明度也能配合不同的字型大小和樣式。

我可以為倒影效果設定哪些屬性?
您可以調整倒影的位置、角度、透明度和顏色等屬性,以配合不同的文件風格。以下說明各項屬性的用途:
哪些屬性控制倒影外觀?
SchemeColor:取得或設定倒影的配色。可用任意色彩為倒影上色,模擬水面或金屬表面。HorizontalSkewAngle:取得或設定水平傾斜角度(度)。 創造透視效果,讓倒影退到遠方。HorizontalScalingFactor:取得或設定水平縮放比例。低於 100 時會壓縮倒影,高於 100 時則會拉伸。DistanceFromText:取得或設定倒影與文字的距離,以點為單位(1 點等於 1/72 英吋)。數值越小,倒影越靠近文字,數值越大,越像映在遠處的表面。DirectionAngle:取得或設定方向角度(度),決定視覺上光源所在的方向。FadeDirectionAngle:取得或設定淡出的方向(度)。可垂直淡出以模擬地面倒影,也可斜向淡出以模擬水面倒影。EndPosition:取得或設定結束位置。 確定倒影完全淡出的位置。StartPosition:取得或設定起始位置。通常設為 0,讓倒影從文字正下方開始。EndingOpacity:取得或設定結束不透明度。 較低的數值會產生微妙的倒影,逐漸變得透明。VerticalScalingFactor:取得或設定垂直縮放比例。負值會將文字上下翻轉,絕對值決定倒影高度。StartingOpacity:取得或設定起始不透明度。數值越高,倒影在起始位置越明顯。Alignment:取得或設定對齊方式。 從各種選項中選擇相對於文字的倒影位置。BlurRadius:取得或設定模糊半徑,以點為單位(1/72英吋)。 較高的值會產生較柔和、較散的倒影。VerticalSkewAngle:取得或設定垂直傾斜角度(度)。 用於建立斜面倒影效果。
如何建立自訂倒影效果?
自訂倒影效果可讓您配合組織的品牌或建立獨特的視覺風格。 以下範例展示了金色的倒影,搭配特定的定位和不透明度設定,為證書、獎項或優質文件標頭創造出專業的外觀。
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ReflectionEffect = new Reflection()
{
Alignment = RectangleAlignmentValues.BottomLeft,
BlurRadius = 5,
DirectionAngle = 90,
DistanceFromText = 5,
EndingOpacity = 100,
EndPosition = 10,
FadeDirectionAngle = 90,
HorizontalScalingFactor = 100,
HorizontalSkewAngle = 0,
SchemeColor = IronWord.Models.Color.Gold,
StartingOpacity = 0,
StartPosition = 0,
VerticalScalingFactor = -100,
VerticalSkewAngle = 0,
},
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Customized reflection"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("customizedReflectionEffect.docx");using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ReflectionEffect = new Reflection()
{
Alignment = RectangleAlignmentValues.BottomLeft,
BlurRadius = 5,
DirectionAngle = 90,
DistanceFromText = 5,
EndingOpacity = 100,
EndPosition = 10,
FadeDirectionAngle = 90,
HorizontalScalingFactor = 100,
HorizontalSkewAngle = 0,
SchemeColor = IronWord.Models.Color.Gold,
StartingOpacity = 0,
StartPosition = 0,
VerticalScalingFactor = -100,
VerticalSkewAngle = 0,
},
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Customized reflection"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("customizedReflectionEffect.docx");Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ReflectionEffect = New Reflection() With {
.Alignment = RectangleAlignmentValues.BottomLeft,
.BlurRadius = 5,
.DirectionAngle = 90,
.DistanceFromText = 5,
.EndingOpacity = 100,
.EndPosition = 10,
.FadeDirectionAngle = 90,
.HorizontalScalingFactor = 100,
.HorizontalSkewAngle = 0,
.SchemeColor = IronWord.Models.Color.Gold,
.StartingOpacity = 0,
.StartPosition = 0,
.VerticalScalingFactor = -100,
.VerticalSkewAngle = 0
}
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Customized reflection"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("customizedReflectionEffect.docx")Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ReflectionEffect = New Reflection() With {
.Alignment = RectangleAlignmentValues.BottomLeft,
.BlurRadius = 5,
.DirectionAngle = 90,
.DistanceFromText = 5,
.EndingOpacity = 100,
.EndPosition = 10,
.FadeDirectionAngle = 90,
.HorizontalScalingFactor = 100,
.HorizontalSkewAngle = 0,
.SchemeColor = IronWord.Models.Color.Gold,
.StartingOpacity = 0,
.StartPosition = 0,
.VerticalScalingFactor = -100,
.VerticalSkewAngle = 0
}
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Customized reflection"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("customizedReflectionEffect.docx")自訂倒影會呈現什麼效果?
上面的自訂倒影範例產生了獨特的金色倒影,增強了文件的高級感。 透過調整從 0% 到 100% 的不透明度漸層,倒影創造出一種反向漸層效果,當倒影遠離文字時會變得更強。 此技術對於建立顯眼的標題或強調重要公告非常有效。

倒影效果的最佳實務
在專業文件中套用倒影效果時,可參考以下做法:
低調的效果通常更合適: 商務文件可使用較低的結束不透明度(20–40%),讓倒影凸顯內容又不分散注意力。較強烈的效果適合重視視覺衝擊的行銷資料或簡報。
配合文件風格: 讓倒影的設定與整體設計一致。正式文件適合模糊程度較低的垂直倒影,創意素材則可用傾斜角度和色彩營造藝術效果。
效能考量:複雜的倒影效果與較高的模糊半徑值可能會增加文件大小和處理時間。對於包含大量倒影元素的文件,請測試效能並適當調整屬性。
留意無障礙需求: 倒影等裝飾效果應有助於清楚傳達資訊。請確保主要文字清晰易讀,尤其是必須符合無障礙標準的文件。
常見問題
如何在C# Word文件中為文本添加反射效果?
您可以使用IronWord在C# Word文件中應用反射效果,方法是創建一個TextStyle並將其TextEffect屬性設置為包含ReflectionEffect。然後,將此樣式添加到包含TextContent的Run中,並將其包含在您的文件中。
反射效果在Word文件中有何優勢?
反射效果通過增加深度和現代風格來增強Word文件的視覺吸引力。它們特別適用於通過模擬文本在光亮表面上的外觀來突出顯示標題、標題或重要信息。
在IronWord中處理文本效果時,為什麼TextStyle物件很重要?
TextStyle物件允許您在多個文本元素中一致地管理和應用文本格式。這個集中配置點確保了統一性,並使在IronWord中全局更新樣式更為高效。
IronWord中的默認反射效果看起來如何?
IronWord中的默認反射效果會在文本下方創建一個微妙的鏡像,具有自動不透明度漸變,這與各種字體大小和樣式相得益彰,非常適合商業文件和演示文稿。
在IronWord中可以為反射效果配置哪些屬性?
您可以為IronWord中的反射效果配置多種屬性,包括顏色、縮放、距離、透明和傾斜角度。每個屬性都使您能夠根據文檔的設計需求量身定制反射效果。
如何在IronWord中創建自定義的反射效果?
要在IronWord中創建自定義反射效果,請修改ReflectionEffect配置中的屬性,例如SchemeColor、HorizontalScalingFactor和VerticalSkewAngle。這可以讓您實現獨特的視覺風格,如帶有金色色調或傾斜的反射。
在專業文件中使用反射效果的最佳做法是什麼?
對於專業文件,使用具有較低不透明度和最小模糊的微妙反射效果。確保樣式與文檔的整體設計保持一致,並在使用複雜效果時考慮性能以避免增加文件大小和處理時間。
自定義IronWord中的反射效果是否會影響文檔性能?
是的,特別是那些具有高模糊半徑設置的高度複雜的反射效果可能會增加文件大小和處理時間。建議測試性能並在文檔中包含大量反射元素時調整這些屬性。
如何在Word文件中使反射效果符合無障礙標準?
反射效果應用於增強而不是取代可讀文本。確保主要內容保持清晰可讀,並始終檢查無障礙標準,特別是在創建面向公眾或合規要求的文檔時。
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。