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
 

Fill ellipse with image in VB - C #.net.

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

In this simple article you will learn that how to fill ellipse with an 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 fill an ellipse with an image of an image.

Create a graphics object. 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 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(Brushes.White, ClientRectangle);

VB:

g.FillRectangle(Brushes.White, ClientRectangle)

Similarly, graphics class provides you a function named as FillEllipse(). 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 FillEllipse() function is:

C#:

g.FillEllipse(tBrush, ClientRectangle);

VB:

g.FillEllipse(tBrush, ClientRectangle)

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;

            SetStyle(ControlStyles.Opaque, true);

            theImage = new Bitmap("Winter.jpg");

            smallImage = new Bitmap(theImage, new Size(theImage.Width / 2, theImage.Height / 2));

            g.FillRectangle(Brushes.White, ClientRectangle);

            Brush tBrush = new TextureBrush(smallImage, new Rectangle(0, 0, smallImage.Width, smallImage.Height));

            g.FillEllipse(tBrush, ClientRectangle);

            tBrush.Dispose();

        }

VB:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

    Dim g As Graphics = e.Graphics

    SetStyle(ControlStyles.Opaque, True)

    theImage = New Bitmap("Winter.jpg")

    smallImage = New Bitmap(theImage, New Size(theImage.Width / 2, theImage.Height / 2))

    g.FillRectangle(Brushes.White, ClientRectangle)

    Dim tBrush As Brush = New TextureBrush(smallImage, New Rectangle(0, 0, smallImage.Width, smallImage.Height))

    g.FillEllipse(tBrush, ClientRectangle)

    tBrush.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"

    End Sub

This simple article tells that how to fill an ellipse with an image in vb and C #.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to do drawing on form using mouse in VB.net - C #.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net