VB.NET tutorial-fill shapes with HatchBrush

Fill shapes with HatchBrush

In this page you will learn to fill the closed shapes using different patterns. By using HatchBrush object created from the HatchBrush class you can fill the shapes with different patterns. The HatchBrush class can be found in System.Drawing.Drawing2D library.

Example: filling the rectangle, pie, and ellipse with different patterns

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 HatchBrush(HatchStyle.DashedHorizontal, Color.FromArgb(10, 250, 100, 0))

        Dim br1 As New HatchBrush(HatchStyle.DiagonalBrick, Color.FromArgb(100, 0, 100, 0))

        Dim br2 As New HatchBrush(HatchStyle.Divot, Color.FromArgb(25, 250, 100, 0))


        '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 to fill shapes with pattersn using Hatch 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.