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
 

Get horizontal - vertical resolution clip bounds and clear the frame using “graphics” class in vb.net - C# .net.

Author: Maliha Atteeq
Download Source Code : 1043_apps.zip

In this simple article you will learn that how can we get the horizontal, vertical, resolution, clip bounds and how to clear the frame using “graphics” class in vb and C# .net.

 Graphics:

This is the very important class for making graphics of your own using c#. This class cannot be inherited. This class provides us a number of different methods for graphics creation. By using these methods you can create graphics of your own choice.

Clear the frame:

In order to clear the graphics on the frame, the graphics class provides us a function named as clear(). This function takes one argument as a parameter of color class. It clears the graphics from the frame and set your specified color on the frame. The return type of this function is void.

To demonstrate make a new window application. Darg one button on the form and write the following code:

C#:

private void btn_clear_Click(object sender, EventArgs e)

        {

            obj.Clear(Color.Azure);

            MessageBox.Show("Frame is cleared");

        }

VB:

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

        obj.Clear(Color.Azure)

        MessageBox.Show("Frame is cleared")

    End Sub

Get the horizontal resolution:

In order to get the horizontal resolution, graphics class provides us a property named as DpiX. This property only gets the resolution and it doesnot set the resolution specified by you. The return type of this property is float.

To demonstrate make a new window application. Darg one button on the form and write the following code:

C#:

  private void btn_getH_Click(object sender, EventArgs e)

        {

            float horizon;

            horizon=obj.DpiX;

            MessageBox.Show("the horizontal resolution is "+Convert.ToString(horizon));

 

        }

VB:

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

    Dim horizon As Single

    horizon = obj.DpiX

 

    MessageBox.Show("the horizontal resolution is " & Convert.ToString(horizon))

End Sub

Get the vertical resolution:

In order to get the vertical resolution, graphics class provides us a property named as DpiY. This property only gets the resolution and it doesnot set the resolution specified by you. The return type of this property is float.

To demonstrate make a new window application. Darg one button on the form and write the following code:

C#:

private void btn_getV_Click(object sender, EventArgs e)

        {

            float vertics;

            vertics = obj.DpiY;

            MessageBox.Show("the vertical resolution is " + Convert.ToString(vertics));

 

        }

VB:

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

    Dim vertics As Single

    vertics = obj.DpiY

 

    MessageBox.Show("the vertical resolution is " & Convert.ToString(vertics))

End Sub

 

 

Get the clip bound:

In order to get the clip bound, graphics class provides us a property named as VisibleClipBounds.This property only gets the bound of the clip and it doesnot set the bounds specified by you. The return type of this property is RectangleF, so it return the x and y component and the width and height of the clip in the object of rectangleF.

To demonstrate make a new window application. Darg one button on the form and write the following code:

C#:

private void btn_getBOund_Click(object sender, EventArgs e)

        {

            RectangleF bounds;

            bounds=obj.VisibleClipBounds;

            MessageBox.Show("the clip bound is " + Convert.ToString(bounds));

        }

VB:

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

    Dim bounds As RectangleF

    bounds = obj.VisibleClipBounds

    MessageBox.Show("the clip bound is " & Convert.ToString(bounds))

End Sub

Check that clipping region is empty or not:

In order to chech that whether the clipping region is empty or it contains a graphics, graphics class provides us a property named as IsClipEmpty. This property returns true if the clipping region is empty otherwise it will return false. The return type of this property is boolean.

To demonstrate make a new window application. Darg one button on the form and write the following code:

C#:

private void btn_chck_Click(object sender, EventArgs e)

        {

            bool clip;

            clip=obj.IsClipEmpty;

            MessageBox.Show("the clipping region is "+Convert.ToString(clip));

        }

VB:

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

    Dim clip As Boolean

    clip = obj.IsClipEmpty

    MessageBox.Show("the clipping region is " & Convert.ToString(clip))

End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP GRAPHICS APPLICATION";

            obj = this.CreateGraphics();

        }

VB:

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

    Me.Text = "DEVASP GRAPHICS APPLICATION"

    obj = Me.CreateGraphics()

End Sub

This simple article tells that how can we get the horizontal, vertical, resolution, clip bounds and how to clear the frame using “graphics” class in vb and C# .net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get host name - port and path of website using “Uri Builder” class vb.net - C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net