VB 2008 Tutorial - Points, Sizes and Rectangles
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
4 posts
Page 1 of 1
Hi, Now i`m gonna show about Points, Sizes and Rectangles
A fundamental concept for any graphics system is the way that positions or sizes are represented. GDI+ uses specialist objects that enable you to specify a point in two dimensional space, a size or a complete rectangle having both location and size.
Points
Coordinates in GDI+ are represented by the Point or PointF structures. These both contain an X and Y member that hold the coordinates for the two axes of the drawing surface. Point structures store the values as integers and PointF structures store them as floating point values. Remember that GDI+ uses floating point values internally so the values in the Point structure will be interpreted by the drawing system as a float or a single for the purpose of creating the graphics.
Some drawing methods, such as DrawLine, are overloaded to accept either X,Y coordinate values or two Point or PointF structures as parameters. The following listing shows two line drawing directives that are functionally identical.
Sizes
Sizes in GDI+ are specified by Width and Height. Just like the Point and PointF, the size comes in two flavours, Size and SizeF with the first storing Width and Height as integers and the second storing them as floating point float or Single values.
Rectangles
Shapes drawn on GDI+ surfaces, such as ellipses or rectangles, are defined by their location which corresponds to the top-left corner of the shape and their width and height defined by a size structure. These two entities, Location and Size are most often used to create a single rectangle definition. Continuing the pattern seen in Points and Sizes, the rectangle too has integer and floating-point versions Rectangle and RectangleF. clapper;
Internally, the Rectangle stores the X and Y position of the top-left corner, the Width and the Height. These may be read or manipulated as Location and Size. The Rectangle will also return useful values such as Left, Right, Top and Bottom as individual values. :P
The code shown in listing 2 creates the effect shown in Figure 1.
Figure 1 [Screenshot of black and white checks made by GDI+ coding]
![Image]()
You can make this checks using this code
Just copy and paste this code below Public Class Form1 and debug, You can see this black and white checks around a form ;)
You can make circles, squrea and more shapes with this code, You can change sizes of each checks, Colours and you can learn a lot to make GDI+ Points, Sizes and Rectangles wahooo;
*******************Thanks for reading my tutorial, I think this Tutorial will be most helpful to you!*******************
If you want any custom tutorial for you or you need any help in VS.NET, VB.NET, Software Coding, Designing and much more any help in Computer stuffs just ask me
Mostly i will help everyone in coding and design stuffs in on Computer
- Best regards hehaho;
- Tvs Praveen wahooo;
- Thanks CodeNStuff! for this amazing Website cooll;
A fundamental concept for any graphics system is the way that positions or sizes are represented. GDI+ uses specialist objects that enable you to specify a point in two dimensional space, a size or a complete rectangle having both location and size.
Points
Coordinates in GDI+ are represented by the Point or PointF structures. These both contain an X and Y member that hold the coordinates for the two axes of the drawing surface. Point structures store the values as integers and PointF structures store them as floating point values. Remember that GDI+ uses floating point values internally so the values in the Point structure will be interpreted by the drawing system as a float or a single for the purpose of creating the graphics.
Some drawing methods, such as DrawLine, are overloaded to accept either X,Y coordinate values or two Point or PointF structures as parameters. The following listing shows two line drawing directives that are functionally identical.
Code: Select all
You can see that the first line takes discrete values and the second directive takes points that were created earlier.myGraphics.DrawLine(Pens.Black,10,20,210,50);
Point p1=new Point(10,20);
Point p2=new Point(210,50);
myGraphics.DrawLine(Pens.Black,p1,p2);
myGraphics.DrawLine(Pens.Black,10,20,210,50)
Dim p1 As new Point(10,20)
Dim p2 As new Point(210,50)
myGraphics.DrawLine(Pens.Black,p1,p2)
Sizes
Sizes in GDI+ are specified by Width and Height. Just like the Point and PointF, the size comes in two flavours, Size and SizeF with the first storing Width and Height as integers and the second storing them as floating point float or Single values.
Rectangles
Shapes drawn on GDI+ surfaces, such as ellipses or rectangles, are defined by their location which corresponds to the top-left corner of the shape and their width and height defined by a size structure. These two entities, Location and Size are most often used to create a single rectangle definition. Continuing the pattern seen in Points and Sizes, the rectangle too has integer and floating-point versions Rectangle and RectangleF. clapper;
Internally, the Rectangle stores the X and Y position of the top-left corner, the Width and the Height. These may be read or manipulated as Location and Size. The Rectangle will also return useful values such as Left, Right, Top and Bottom as individual values. :P
The code shown in listing 2 creates the effect shown in Figure 1.
Figure 1 [Screenshot of black and white checks made by GDI+ coding]

You can make this checks using this code

Just copy and paste this code below Public Class Form1 and debug, You can see this black and white checks around a form ;)
You can make circles, squrea and more shapes with this code, You can change sizes of each checks, Colours and you can learn a lot to make GDI+ Points, Sizes and Rectangles wahooo;
Code: Select all
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim smallSquareSize As New SizeF(0.1F * Me.ClientRectangle.Width, _
0.1F * Me.ClientRectangle.Height)
'create the brush
Dim sb As New SolidBrush(Color.White)
'toggle between black and white squares
Dim toggle As Boolean = False
'ten steps down
Dim y As Integer
For y = 0 To 9
'ten steps across
Dim x As Integer
For x = 0 To 9
'select the brush colour
If toggle Then
sb.Color = Color.Black
Else
sb.Color = Color.White
End If 'create a rectangle
Dim rc As New RectangleF(x * smallSquareSize.Width, _
y * smallSquareSize.Height, smallSquareSize.Width, smallSquareSize.Height)
'fill it with the colour
e.Graphics.FillRectangle(sb, rc)
'swop the colour
toggle = Not toggle
Next x
'swop the colour at the line ends
toggle = Not toggle
Next y
'recycle the brush
sb.Dispose()
End Sub 'Form1_Paint
*******************Thanks for reading my tutorial, I think this Tutorial will be most helpful to you!*******************
If you want any custom tutorial for you or you need any help in VS.NET, VB.NET, Software Coding, Designing and much more any help in Computer stuffs just ask me
Mostly i will help everyone in coding and design stuffs in on Computer
- Best regards hehaho;
- Tvs Praveen wahooo;
- Thanks CodeNStuff! for this amazing Website cooll;
4 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023