A brush is similar to a pen except it does not have a width. Change the code as shown below:
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, 3) 'Black, width of 3 Dim MyBrush As New SolidBrush(Color.LawnGreen) Me.CreateGraphics.FillEllipse(MyBrush, e.X - 15, e.Y - 15, 30, 30) Me.CreateGraphics.DrawEllipse(MyPen, e.X - 15, e.Y - 15, 30, 30) End Sub 'Form1_MouseClick
Because we first draw the circle with the brush, then draw a circle on top of it with the pen, we get a solid green circle with a black outline. We have also modified the code so that the center of the circle is at the point clicked.
Experiment: Use other colors, and other size ellipses. See if you can duplicate the program in the illustration. (You need two brushes.)
The pen is used with Draw methods and the brush is used with Fill methods. Using the code above as an example, draw rectangles instead of circles:
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, 3) 'Black, width of 3
Dim MyBrush As New SolidBrush(Color.LawnGreen)
Me.CreateGraphics.FillRectangle(MyBrush, e.X - 15, e.Y - 15, 30, 30)
Me.CreateGraphics.DrawRectangle(MyPen, e.X - 15, e.Y - 15, 30, 30)
End Sub 'Form1_MouseClick