Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to use Textured Brush on image in VB - C #.net.

Author: Maliha Atteeq
Download Source Code : 1087_code.zip

In this simple article you will learn that how to use Textured Brush on image in vb and C #.net.

 Graphics:

While playing with the graphics you must keep the following point in your mind:

You can’t draw graphics on simple load event of the form. To create graphics on the form, you must override the onpaint() function of the form.

The syntax of the onpaint() function is:

C#:

protected override void OnPaint (PaintEventArgs e)

{

}

VB:

Protected Overrides Sub OnPaint(ByVal As PaintEventArgs)
        
    
End Sub

In this article I will tell you that how can we draw a string on an image using textured brush.

Texture Brush:

A texture brush is an object that holds a picture and uses it to regularly fill the interior of a closed shape. To initialize it, you can use an existing picture designed by someone else or you can design your own picture using any normal graphics application, including Microsoft Paint. You should have the picture as a file with a normal graphics file extension, which could be .bmp

In order to write a string, first of all you have to create two images of any type of your choice ang their textured brushes. Load them in the form load event. After you load these things, then to display the graphics you have to override the function onpaint(). Create a graphics and a rectangle object. Graphics class provides you a function named as FillRectangle(). This function has three overloaded methods depending on your requirrements you can use any of them. The return type of this function is void.

The syntax of the FillRectangle() function is:

C#:

g.FillRectangle(texturedBGroundBrush, r);

VB:

g.FillRectangle(texturedBGroundBrush, r)

the next function is the drawString(). This function has five overloaded methods,depending ob your requirements you can use any of them. The return type of this function is void.

The syntax of the Drawstring() function is:

C#:

g.DrawString("Bitmaps as brushes",new Font("Arial", 30,FontStyle.Bold | FontStyle.Italic),texturedTextBrush,r);

VB:

g.DrawString("Bitmaps as brushes", New Font("Arial", 30, FontStyle.Bold Or FontStyle.Italic), texturedTextBrush, r)

 

To demonstrate make a new window application and write the following code on form’s onpaint event:

C#:

protected override void  OnPaint(PaintEventArgs e)

        {

            Graphics g = e.Graphics;

            Rectangle r = ClientRectangle;

            g.FillRectangle(texturedBGroundBrush, r);

            g.DrawString("Bitmaps as brushes",new Font("Arial", 30,FontStyle.Bold | FontStyle.Italic),texturedTextBrush,r);

 

        }

VB:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

    Dim g As Graphics = e.Graphics

    Dim r As Rectangle = ClientRectangle

    g.FillRectangle(texturedBGroundBrush, r)

    g.DrawString("Bitmaps as brushes", New Font("Arial", 30, FontStyle.Bold Or FontStyle.Italic), texturedTextBrush, r)

 

End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

                       this.Text = "DEVASP  APPLICATION";

          Image bGroundBrushImage = new Bitmap("Sunset.jpg");

          texturedBGroundBrush = new TextureBrush(bGroundBrushImage);

          Image textBrushImage = new Bitmap("blue hills.jpg");

          texturedTextBrush = new TextureBrush(textBrushImage);

           

        }

Vb:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

 

  Me.Text = "DEVASP  APPLICATION"

Dim bGroundBrushImage As Image = New Bitmap("Sunset.jpg")

texturedBGroundBrush = New TextureBrush(bGroundBrushImage)

Dim textBrushImage As Image = New Bitmap("blue hills.jpg")

texturedTextBrush = New TextureBrush(textBrushImage)

    End Sub

This simple article tells that how to use Textured Brush on image in vb and C #.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to make reflection of an image in VB.net - C #.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net