Dodaj efekt gradientu

Stosowanie efektów gradientu na tekście

Efekt gradientu w IronWord pozwala na wyświetlanie przejść kolorów w tekście, tworząc wizualnie atrakcyjne projekty. 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. Te gotowe ustawienia upraszczają proces dodawania profesjonalnie wyglądających gradientów bez ręcznej konfiguracji punktów stopu koloru.

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. Takie ustrukturyzowane podejście zapewnia prawidłowe zastosowanie i zachowanie efektu gradientu w wyjściowym dokumencie.

Wyjaśnienie kodu

Powyższy kod pokazuje, jak zastosować efekt gradientu na tekście. Najpierw tworzy nowy dokument 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. To odzwierciedla hierarchię dokumentu: Dokument → Akapit → Fragment tekstu → Zawartość tekstu. Na koniec nowy dokument Word jest eksportowany.

Aby uzyskać więcej przykładów i demonstracji, proszę przejść do następującego artykułu: Jak dodać efekt gradientu do tekstu.

Tutaj znajdziesz więcej poradników na temat elementów dokumentu Word

Gotowy, aby rozpocząć?
Nuget Pliki do pobrania 44,829 | Wersja: 2026.5 just released
Still Scrolling Icon

Wciąż przewijasz?

Czy chcesz szybko dowodu? PM > Install-Package IronWord
uruchom próbkę zobacz, jak twoje dane stają się dokumentem Word.