Rectangles

experimentSome of the graphics methods use rectangles. A rectangle is another class. When you declare an instance of the rectangle class, you give X, Y, width and height as the arguments. Previously, we asked you to copy the program using two brushes. here we show how to change the color of MyBrush after it has been declared.
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
   Dim MyBrush As New SolidBrush(Color.Black)
   Dim MyRectangle As New Rectangle(e.X, e.Y, 20, 20)
   Me.CreateGraphics.FillEllipse(MyBrush, MyRectangle)
   MyRectangle.X = MyRectangle.X + 3
   MyRectangle.Y = MyRectangle.Y + 3
   MyBrush.Color = Color.DeepPink
   Me.CreateGraphics.FillEllipse(MyBrush, MyRectangle)
End Sub 'Form1_MouseClick

More Shapes

arc

Dim MyPen As New Pen(Color.Red, 3)
Me.CreateGraphics.DrawArc(MyPen, e.X, e.Y, 40, 40, 0, 90)
'pen, center of circle as x, and Y, width and height of circle, start angle, degrees)
fillPie
Dim MyBrush As New SolidBrush(Color.Blue)
Me.CreateGraphics.FillPie(MyBrush, e.X, e.Y, 40, 40, 90, 180)

happy face A Happy Face using several drawing methods:
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As _ 
    System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
  Dim MyPen As New Pen(Color.Black, 2)
  Dim MyBrush As New SolidBrush(Color.Yellow)
  Dim MyRect As New Rectangle(e.X - 20, e.Y - 20, 40, 40)
  Me.CreateGraphics.FillEllipse(MyBrush, MyRect) 'yellow head
  Me.CreateGraphics.DrawEllipse(MyPen, MyRect) 'black outline
  MyPen.Color = Color.DarkRed 'red for mouth
  Me.CreateGraphics.DrawArc(MyPen, e.X - 12, e.Y - 12, 25, 25, 0, 180) 'mouth
  MyBrush.Color = Color.DarkBlue 'blue for eyes
  Me.CreateGraphics.FillEllipse(MyBrush, e.X - 12, e.Y - 10, 8, 8) 'left eye
  Me.CreateGraphics.FillEllipse(MyBrush, e.X + 4, e.Y - 10, 8, 8) 'right eye
End Sub 'Form1_MouseClick

INDEX, Draw a circle, The Brush, Drawing rectangles, Arc and Pie, Array of Points, Drawing Strings: The Font Class, Numbered Dots Project, Numbered Dots Solution
Next lesson: Procedures in Visual Basic

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Arc and Pie