如何為文字添加外框效果

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

文字外框效果在文本字符周圍添加一個可見的邊框,創造出一個明確的輪廓,從而增強可讀性或視覺衝擊力。此效果可以根據顏色、厚度和樣式來進行自訂,以符合設計偏好。這種效果常用於圖形、排版和數字設計中,使文本在背景前突出或創造出別具一格的外觀。

C# NuGet 程式庫用于

安裝與 NuGet

Install-Package IronWord
C# NuGet 程式庫用于

安裝與 NuGet

Install-Package IronWord
Java PDF JAR

下載 DLL

下載DLL

手動安裝到您的項目中

立即開始在您的專案中使用IronPDF,並享受免費試用。

第一步:
green arrow pointer

查看 IronWordNuget 快速安裝和部署。已被下載超過800萬次,它正用C#改變。

C# NuGet 程式庫用于 nuget.org/packages/IronWord/
Install-Package IronWord

增加文字描邊效果

要為文字指定描邊效果,請創建 TextStyle 對象並使用 TextOutlineEffect 對象填充 TextOutlineEffect 屬性。最後,通過將 TextStyle 對象分配給 TextEffect 屬性來添加具有該樣式的新文字。

:path=/static-assets/word/content-code-examples/how-to/text-effect-text-outline-effect.cs
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()
{
    TextOutlineEffect = TextOutlineEffect.DefaultEffect,
};

// Add text with style
doc.AddText("Hello World").Style = textStyle;

// Export new Word document
doc.SaveAs("textOutlineEffect.docx");
Imports IronWord
Imports IronWord.Models

' Create new Word document
Private doc As New WordDocument()

' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {.TextOutlineEffect = TextOutlineEffect.DefaultEffect}

' Add text with style
doc.AddText("Hello World").Style = textStyle

' Export new Word document
doc.SaveAs("textOutlineEffect.docx")
VB   C#
添加文字輪廓效果

文字輪廓效果屬性

文字輪廓效果提供了多種可自定義的屬性,以滿足任何設計需求。請參閱以下屬性及其描述:

  • PenAlignment:獲取或設置用於輪廓效果的筆對齊方式。
  • LineCapType:獲取或設置用於輪廓效果的線帽類型。
  • LineWidth:獲取或設置輪廓效果線條的寬度。 (備註:寬度以點數指定 (1/72英寸).)
  • CompoundLineType: 獲取或設置用於輪廓效果的複合線類型。
  • LineJoin: 獲取或設置用於輪廓效果的描邊連接樣式。
  • Color: 獲取或設置輪廓效果的純色填充顏色。
  • presetLineDash: 獲取或設置用於輪廓效果的預設線條虛線樣式。
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-text-outline-effect.cs
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()
{
    TextOutlineEffect = new TextOutlineEffect()
    {
        Color = IronWord.Models.Color.Red,
        CompoundLineType = CompoundLineValues.Double,
        LineCapType = LineCapValues.Round,
        LineJoin = StrokeJoinStyleValues.Bevel,
        LineWidth = 0.3,
        PenAlignment = PenAlignmentValues.Center,
        presetLineDash = PresetLineDashValues.Solid
    },
};

// Add text with style
doc.AddText("Customized text outline").Style = textStyle;

// Export new Word document
doc.SaveAs("customizedTextOutlineEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums

' Create new Word document
Private doc As New WordDocument()

' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
	.TextOutlineEffect = New TextOutlineEffect() With {
		.Color = IronWord.Models.Color.Red,
		.CompoundLineType = CompoundLineValues.Double,
		.LineCapType = LineCapValues.Round,
		.LineJoin = StrokeJoinStyleValues.Bevel,
		.LineWidth = 0.3,
		.PenAlignment = PenAlignmentValues.Center,
		.presetLineDash = PresetLineDashValues.Solid
	}
}

' Add text with style
doc.AddText("Customized text outline").Style = textStyle

' Export new Word document
doc.SaveAs("customizedTextOutlineEffect.docx")
VB   C#
自定義文字輪廓效果