Comment ajouter un effet de contour au texte en C# | IronWord

How to Add Text Outline Effect to Text

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

A text outline effect adds a visible border around the characters of text, creating a defined outline that enhances readability or visual impact. This effect can be customized in terms of color, thickness, and style to suit design preferences. It's commonly used in graphics, typography, and digital design to make text stand out against backgrounds or to create a stylized appearance.

Quickstart: Apply a Default Text Outline Effect Instantly

With just one line, create a TextStyle that applies a ready-made text outline via TextOutlineEffect.DefaultEffect. It’s a fast way to let developers use IronWord to make text stand out without complex setup.

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.

    new IronWord.Models.TextStyle { TextEffect = new IronWord.Models.TextEffect { TextOutlineEffect = IronWord.Models.TextOutlineEffect.DefaultEffect } }
  3. Deploy to test on your live environment

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

Add Text Outline Effect

To specify the text outline effect for the text, create the TextStyle object and populate the TextOutlineEffect property with a TextOutlineEffect object. Finally, add new text with the style by assigning the TextStyle object to the TextEffect property.

: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")
$vbLabelText   $csharpLabel
Add text outline effect

Text Outline Effect Properties

The text outline effect offers a variety of customizable properties to suit any design need. Below are the properties along with their descriptions:

  • PenAlignment: Gets or sets the alignment of the pen used for the outline effect.
  • LineCapType: Gets or sets the type of line cap used for the outline effect.
  • LineWidth: Gets or sets the width of the outline effect line. Note: The width is specified in points (1/72 inch).
  • CompoundLineType: Gets or sets the type of compound line used for the outline effect.
  • LineJoin: Gets or sets the stroke join style used for the outline effect.
  • Color: Gets or sets the solid fill color for the outline effect.
  • PresetLineDash: Gets or sets the preset line dash style for the outline effect.
: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")
$vbLabelText   $csharpLabel
Customized text outline effect

Questions Fréquemment Posées

Qu'est-ce qu'un effet de contour de texte dans un document Word?

Un effet de contour de texte dans un document Word ajoute une bordure visible autour des caractères du texte, améliorant ainsi leur lisibilité et leur impact visuel. Cet effet est personnalisable en termes de couleur, d'épaisseur et de style pour mieux répondre aux préférences de design.

Comment puis-je appliquer un effet de contour de texte en C#?

En C#, vous pouvez appliquer un effet de contour de texte en utilisant la classe TextOutlineEffect dans IronWord. Vous pouvez configurer ses propriétés telles que la couleur, la largeur des lignes et le style pour personnaliser l'effet pour votre texte.

Quelles sont les étapes pour ajouter un effet de contour de texte avec IronWord?

Les étapes comprennent le téléchargement de la bibliothèque IronWord, l'application de l'effet de texte au nouveau ou ancien texte, la configuration des propriétés de TextOutlineEffect, et l'exportation du document édité en tant que nouveau fichier.

Puis-je personnaliser les propriétés d'un effet de contour de texte en C#?

Oui, vous pouvez personnaliser l'effet de contour de texte en ajustant des propriétés comme PenAlignment, LineCapType, LineWidth, CompoundLineType, LineJoin, Color, et PresetLineDash en utilisant IronWord.

Quelle est l'unité de mesure pour la largeur des lignes dans un effet de contour de texte?

La largeur des lignes pour un effet de contour de texte est mesurée en points, où un point équivaut à 1/72 de pouce.

Comment puis-je exporter un document Word après avoir appliqué un effet de contour de texte?

Après avoir appliqué un effet de contour de texte dans IronWord, vous pouvez exporter le document Word modifié en utilisant les fonctions d'exportation de la bibliothèque pour enregistrer vos modifications en tant que nouveau fichier.

Quel est le but d'utiliser des effets de contour de texte dans la conception?

Les effets de contour de texte sont utilisés pour faire ressortir le texte par rapport à un arrière-plan ou pour créer une apparence stylisée, améliorant ainsi la lisibilité et l'impact visuel dans le design numérique.

Comment puis-je définir un style de texte avec un effet de contour de texte en C#?

Vous pouvez définir un style de texte en créant un objet TextStyle et en remplissant sa propriété TextOutlineEffect avec un objet TextOutlineEffect. Assignez ce style à votre texte via la propriété TextEffect.

Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Nuget Téléchargements 25,807 | Version : 2025.11 vient de sortir