Graphics features of vb.net

Graphics features of vb.net

There are many other methods you can use with a graphics object besides the DrawRectangle and FillRectangle methods illustrated in this example. Use DrawEllipse to draw circles and other round objects, and also try DrawLine, DrawPolygon, and others. The four arguments at the end of this line of code describe the horizontal (12) and vertical (15) point on the form where the upper-left corner of your rectangle is located, and the width (36) and height (45) of the rectangle: grObj.FillRectangle(brushBlue, 12, 15, 36, 45) The PSet and Point commands, which allowed you to manipulate individual pixels in earlier versions of VB, can be simulated by using the SetPixel or GetPixel methods of the System.Drawing Bitmap class. You can create a solid graphic (a square, circle, and so on) by simply using a brush to fill the area, without first using a pen to draw an outline

==========================================================================

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'create graphics object

Dim grObj As System.Drawing.Graphics

grObj = Me.CreateGraphics

'create a red pen

Dim penRed As New System.Drawing.Pen(System.Drawing.Color.PaleVioletRed)

'make it fairly wide

penRed.Width = 9

'draw a square

grObj.DrawRectangle(penRed, 12, 12, 45, 45)

'create a brush (to fill the square)

Dim brushBlue As System.Drawing.Brush

brushBlue = New SolidBrush(Color.DarkBlue)

grObj.FillRectangle(brushBlue, 12, 12, 45, 45)

End Sub

=========================================================================

No comments: