Brushes in WPF using VB.NET: Part 2

In this article you learn about the all types of brushes and how to working with them in WPF.
  • 2563
 

Brushes: As you learn in my previous article part 1 a brush is used to describe the background of a button, the foreground of text, and the fill of a shape and all brushes classes are inherit from System.Windows.Media.Brush and give you more exotic effects.

Here we discuss about the second Brush class that is LinearGradientBrush.

LinearGradientBrush: The LinearGradientBrush allows you to create a blended fill that changes from one color to another a linear gradient blends two or more colors across a line, the gradient axis. You use GradientStop objects to specify the colors in the gradient and their positions. In simple words we can describe the LinearGradientBrush as it paints an area using a radial gradient fill, which is similar to a linear gradient except it radiates out in a circular pattern starting from a center point.

Example of an LinearGradientBrush
Xaml Code

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Rectangle Width="70" Height="70">
        <Rectangle.Fill>
            <LinearGradientBrush>
                <GradientStop Color="Blue" Offset="0.1" />
                <GradientStop Color="Pink" Offset="0.9" />
                <GradientStop Color="Black" Offset="1.1" />
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
</
Window>

VB code

    Dim Rectangle1 As New Rectangle()
        Rectangle1.Width = 70
        Rectangle1.Height = 70
    ' Create a LinearGradientBrush and use it to
    ' paint the rectangle.
    Dim Brush As New LinearGradientBrush()
        Brush.GradientStops.Add(New GradientStop(Colors.blue, 0.1))
        Brush.GradientStops.Add(New GradientStop(Colors.pink, 0.9))
        Brush.GradientStops.Add(New GradientStop(Colors.black,1.1))
 
       Rectangle1.Fill = Brush

Output Window


 brush2.gif

Conclusion

Hope this article will help you understand the working of LinearGradientBrush in WPF. Remaining types of brushes will explain in my next articles.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.