Comment ajouter un effet d'ombre au texte en C# | IronWord

How to Add Shadow Effect to Text

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

The Shadow Effect on text is a visual enhancement technique used to create depth and distinction for text elements. When applied, it introduces a duplicated version of the text behind the original, slightly offset to give the appearance of a shadow. This secondary text, known as the shadow, can be adjusted in several ways to achieve different visual effects.

Quickstart: Add a Preset Shadow Effect in One Line

Here’s how to enhance your Word document text with a shadow using IronWord—just one line to define style and shadow, plus save. Ideal for devs who want results fast with minimal 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.WordDocument().AddText("Shadow!").Style = new IronWord.Models.TextStyle { TextEffect = new IronWord.Models.TextEffect { ShadowEffect = IronWord.Models.Shadow.OuterShadow1 } };
  3. Deploy to test on your live environment

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

Add Shadow Effect

To specify the shadow effect for the text, create the TextStyle object and populate the ShadowEffect property with a Shadow 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-shadow-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()
{
    ShadowEffect = Shadow.OuterShadow1,
};

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

// Export new Word document
doc.SaveAs("shadowEffect.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 {.ShadowEffect = Shadow.OuterShadow1}

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

' Export new Word document
doc.SaveAs("shadowEffect.docx")
$vbLabelText   $csharpLabel
Add shadow effect

Shadow Effect Properties

Besides assigning a predefined shadow value, all of the shadow effect's properties can be configured. This provides a very flexible option to customize the shadow effect in any way possible. Please see the properties and their descriptions below:

  • Alignment: Gets or sets the alignment of the shadow.
  • BlurRadius: Gets or sets the blur radius of the shadow effect. The blur radius is specified in points (1/72 inch).
  • DirectionAngle: Gets or sets the direction angle of the shadow effect. The direction angle is specified in degrees.
  • DistanceFromText: Gets or sets the distance of the shadow effect from the text or object. The distance is specified in points (1/72 inch).
  • HorizontalScalingFactor: Gets or sets the horizontal scaling factor of the shadow effect.
  • HorizontalSkewAngle: Gets or sets the horizontal skew angle of the shadow effect. The skew angle is specified in degrees.
  • SchemeColor: Gets or sets the scheme color of the shadow effect.
  • VerticalScalingFactor: Gets or sets the vertical scaling factor of the shadow effect.
  • VerticalSkewAngle: Gets or sets the vertical skew angle of the shadow effect. The skew angle is specified in degrees.
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-shadow-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()
{
    ShadowEffect = new Shadow()
    {
        Alignment = RectangleAlignmentValues.BottomLeft,
        BlurRadius = 5,
        DirectionAngle = 45,
        DistanceFromText = 3,
        HorizontalScalingFactor = 100,
        VerticalScalingFactor = 100,
        HorizontalSkewAngle = 0,
        SchemeColor = IronWord.Models.Color.Aqua,
        VerticalSkewAngle = 0,
    },
};

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

// Export new Word document
doc.SaveAs("customizedShadowEffect.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 {
	.ShadowEffect = New Shadow() With {
		.Alignment = RectangleAlignmentValues.BottomLeft,
		.BlurRadius = 5,
		.DirectionAngle = 45,
		.DistanceFromText = 3,
		.HorizontalScalingFactor = 100,
		.VerticalScalingFactor = 100,
		.HorizontalSkewAngle = 0,
		.SchemeColor = IronWord.Models.Color.Aqua,
		.VerticalSkewAngle = 0
	}
}

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

' Export new Word document
doc.SaveAs("customizedShadowEffect.docx")
$vbLabelText   $csharpLabel
Customized shadow effect

Questions Fréquemment Posées

Comment puis-je ajouter un effet d'ombre au texte en C# ?

Vous pouvez ajouter un effet d'ombre au texte en C# en utilisant la bibliothèque IronWord. Tout d'abord, téléchargez la bibliothèque, puis appliquez l'effet d'ombre à l'aide de la classe Shadow. Configurez les propriétés selon vos besoins et exportez votre document avec les effets appliqués.

Quelles sont les propriétés personnalisables d'un effet d'ombre dans IronWord ?

IronWord vous permet de personnaliser plusieurs propriétés de l'effet d'ombre, y compris Alignment, BlurRadius, DirectionAngle, DistanceFromText, HorizontalScalingFactor, HorizontalSkewAngle, SchemeColor, VerticalScalingFactor et VerticalSkewAngle.

Comment appliquer un effet d'ombre prédéfini avec IronWord ?

Pour appliquer un effet d'ombre prédéfini avec IronWord, utilisez l'instance nommée statiquement de la classe Shadow et configurez ses propriétés pour répondre à vos besoins.

Puis-je appliquer un effet d'ombre à du texte existant dans un document Word ?

Oui, vous pouvez appliquer un effet d'ombre à du texte nouvellement créé et existant dans un document Word en utilisant IronWord en créant un objet TextStyle et en peuplant la propriété ShadowEffect avec un objet Shadow.

Quel est le rôle de la propriété BlurRadius dans un effet d'ombre ?

La propriété BlurRadius dans un effet d'ombre spécifie le rayon de flou en points (1/72 pouce), ce qui détermine à quel point l'ombre apparaît douce ou nette.

Comment contrôler la direction d'un effet d'ombre dans un document Word ?

Pour contrôler la direction d'un effet d'ombre dans IronWord, réglez la propriété DirectionAngle, qui est spécifiée en degrés, pour orienter l'ombre comme vous le souhaitez.

Est-il possible d'aligner différemment l'ombre par rapport au texte ?

Oui, la propriété Alignment d'IronWord vous permet de définir l'alignement de l'ombre par rapport au texte, offrant une flexibilité dans le positionnement de l'ombre.

Comment définir la couleur d'un effet d'ombre pour correspondre au thème de mon document ?

Utilisez la propriété SchemeColor dans IronWord pour définir le schéma de couleurs de l'effet d'ombre, permettant à l'ombre de correspondre au thème de conception global de votre document.

Que contrôle la propriété DistanceFromText dans un effet d'ombre ?

La propriété DistanceFromText contrôle la distance de l'ombre par rapport au texte ou à l'objet, mesurée en points (1/72 pouce), influençant à quelle distance l'ombre apparaît du texte.

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