Some 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
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)
Dim MyBrush As New SolidBrush(Color.Blue) Me.CreateGraphics.FillPie(MyBrush, e.X, e.Y, 40, 40, 90, 180)
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