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 draw a partial image in VB.net - C #.net.

Author: Maliha Atteeq
Download Source Code : 1089_Kode.zip

In this simple article you will learn that how to draw a partial 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:

Dim e As PaintEventArgs

 

Me.OnPaint(e)

In this article I will tell you that how we can draw a partial image.

Make an object of garaphics and an object of rectangle. There are three constructors for making the rectangle object, depending on your requirements you can select anyone among them.

C#:

Rectangle rect = new Rectangle(95, 5, 50, 55);

VB:

Dim rect As New Rectangle(95, 5, 50, 55)

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

The syntax of the DrawImage() function is:

C#:

g.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel);

VB:

g.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel)

The partial and the full image will be displayed side by side so that you can check the effects. Partial image is actually a small portion of the original image. In partial image you are not decreasing the size of the image; you just take out a small portion from the image.

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 rect = new Rectangle(95, 5, 50, 55);

            g.DrawImage(image, rect);

            g.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel);

        }

         

VB:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

    Dim g As Graphics = e.Graphics

    Dim rect As New Rectangle(95, 5, 50, 55)

    g.DrawImage(image, rect)

    g.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel)

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"

End Sub

This simple article tells that how to make a partial image in VB and C #.net.

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

Disclaimer - Privacy
© 2002-2017 DevASP.net