VB.NET tutorial-fill shapes with LinearGradientBrush

Fill shapes with LinearGradientBrush

Closed shapes(rectangles, ellipses,...) that are drawn on the control can be filled with a mix of colors by using LinearGradientBrush object. You can create a LinearGradientBrush object from the LearnGradientBrush class of System.Drawing.Drawing2D library.

Example: filling the rectangle, pie , and ellipses with a mix of colors

imports System.Drawing.Drawing2D

Public Class Form1


    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint


       'Create brush objects

        Dim br0 As New LinearGradientBrush(New Point(100, 150), New Point(180, 250), Color.DarkBlue, Color.Aqua)

        Dim br1 As New LinearGradientBrush(New Point(190, 120), New Point(410, 240), Color.LightCyan, Color.DarkCyan)

        Dim br2 As New LinearGradientBrush(New Point(320, 100), New Point(470, 250), Color.FromArgb(255, 100, 100, 0), Color.FromArgb(100, 0, 255, 100))


        'Create rectangle objects

        Dim rt0 As New Rectangle(100, 150, 80, 100)

        Dim rt1 As New Rectangle(190, 120, 120, 120)

        Dim rt2 As New Rectangle(320, 100, 150, 150)

        'Fill shapes

        e.Graphics.FillRectangle(br0, rt0)

        e.Graphics.FillPie(br1, rt1, 0, -180)

        e.Graphics.FillEllipse(br2, rt2)


End Sub


End Class


VB.NET example code to fill shapes with gradient brush



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.