VB.NET tutorial-fill shapes with images


Fill shapes with images

Besides filling the shapes with a color, a mix of colors, or patterns,  you can fill the shapes with images. In this page you will learn to fill the closed shapes using different images. To fill the shapes with images, You need to create a TextureBrush object from the TextureBrush class of System.Drawing library and use it to fill your shapes.

Example: filling the rectangle, pie, and ellipse with images

 


Public Class Form1
   
    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       
       'Create image objects
        Dim image0 As Image = Image.FromFile("image0.bmp")
        Dim image1 As Image = Image.FromFile("image1.bmp")
        Dim image2 As Image = Image.FromFile("image2.bmp")
        'Create brush objects with images
        Dim br0 As New TextureBrush(image0)
        Dim br1 As New TextureBrush(image1)
        Dim br2 As New TextureBrush(image2)
        'Create rectangle objects
        Dim rt0 As New Rectangle(50, 100, 200, 200)
        Dim rt1 As New Rectangle(260, 100, 200, 200)
        Dim rt2 As New Rectangle(470, 100, 200, 200)
        '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 images using Texture brush




Comments

CAPTCHA image




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.