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
 

Using Hatch Brush in VB.net - C #.net.

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

In this simple article you will learn that how to use Hatch Brush 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 hatch brush.

Hatch Brush:

A hatch brush relies on a drawn or designed pattern to set its filling type. To support hatch brushes, the .NET Framework provides the patterns you can use as part of the brush. These pre-designed patterns are referred to as hatch styles. This means that when you use a hatch brush, you must specify the type of pattern you want to use, through one of the available hatch styles. To make the filled area more interesting, you also specify the color to use when drawing the pattern. To get a hatch brush, you use the Hatch Brush class. You can use the following constructor of hatch brush class to create its object.

C#:

HatchBrush hb = new HatchBrush(HatchStyle.Cross, Color.White, Color.Black);

VB:

Dim hb As New HatchBrush(HatchStyle.Cross, Color.White, Color.Black)

In order to display the graphics you have to override the function onpaint(). Create a graphics and a rectangle object. Also create an object of hatch brush class, this class can’t be inherited. Graphics class provides you a function named as FillRectangle(). This function has three overloaded methods depending on your requirements 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("Hatch Brush", f, hb, 0, 0);

VB:

g.DrawString("Hatch Brush", f, hb, 0, 0)

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;

            g.FillRectangle(Brushes.White, this.ClientRectangle);

            Font f = new Font("Times New Roman", 48, FontStyle.Bold);

            HatchBrush hb = new HatchBrush(HatchStyle.Cross, Color.White, Color.Black);

            g.DrawString("Hatch Brush", f, hb, 0, 0);

            f.Dispose();

 }         

VB:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

Dim g As Graphics = e.Graphics

g.FillRectangle(Brushes.White, Me.ClientRectangle)

Dim f As New Font("Times New Roman", 48, FontStyle.Bold)

Dim hb As New HatchBrush(HatchStyle.Cross, Color.White, Color.Black)

g.DrawString("Hatch Brush", f, hb, 0, 0)

f.Dispose()

End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

                       this.Text = "DEVASP  APPLICATION";      

        }

VB:

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

  Me.Text = "DEVASP  APPLICATION"

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

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Edge detection in an image using sobel filter in VB.net - C#.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net