Ajouter un effet de dégradé

Appliquer des effets de dégradé au texte

L'effet de dégradé d' IronWord permet d'afficher des transitions de couleur dans le texte, créant ainsi des designs visuellement attrayants. IronWord provides preset gradient options through the Gradient class, such as Gradient.DefaultGray, which can be assigned directly to the GradientEffect property of a TextEffect.

To apply a gradient, create a TextStyle object and configure its TextEffect property with a GradientEffect. The gradient can be set using predefined static instances from the Gradient class, which offer commonly used color schemes and transitions. Ces préréglages simplifient le processus d'ajout de dégradés d'aspect professionnel sans avoir à configurer manuellement les arrêts de couleur.

Once the style is configured, create a Run containing TextContent and assign the style to the run's Style property. Add the run to a paragraph using AddChild, then insert the paragraph into the document. Cette approche structurée garantit que l'effet de dégradé est correctement appliqué et préservé dans le document de sortie.

Explication du code

Le code ci-dessus montre comment appliquer un effet de dégradé à un texte. Tout d'abord, il crée un nouveau document Word. Then, it creates a TextStyle object and configures it to use a gradient effect by assigning the Gradient.DefaultGray preset to the GradientEffect property.

To add the styled text, a Paragraph is created, then a Run object is created containing TextContent with "Hello World". The configured TextStyle is assigned to the Run, applying the gradient effect. The Run is added to the Paragraph using AddChild, and the Paragraph is added to the document. Cela suit la hiérarchie du document : Document → Paragraphe → Run → TextContent. Enfin, le nouveau document Word est exporté.

Pour plus d'exemples et de démonstrations, veuillez consulter l'article suivant : Comment ajouter un effet de dégradé à un texte .

Découvrez d'autres tutoriels sur les éléments de document Word ici

Prêt à commencer?
Nuget Téléchargements 35,581 | Version : 2026.3 vient de sortir
Still Scrolling Icon

Vous faites encore défiler ?

Vous voulez une preuve rapidement ? PM > Install-Package IronWord
exécuter un échantillon regarder vos données devenir un document Word.