Zebra0.com

visual-basic drawing


Public Class Form1
    Dim Number As Integer = 0
    Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
        Dim MyFont As New Font("Courier New", 12, FontStyle.Bold) 'Or do this in the design window
        Dim Red, Green, Blue As Integer
        Red = Rnd() * 255
        Green = Rnd() * 255
        Blue = Rnd() * 255
        Dim MyBrush As New SolidBrush(Color.FromArgb(255, Red, Green, Blue)) 'random color brush
        Me.CreateGraphics.FillEllipse(MyBrush, e.X, e.Y, 20, 20) 'draw the circle
        MyBrush.Color = Color.FromArgb(255, 255 - Red, 255 - Green, 255 - Blue) 'change the brush color
        Number = Number + 1 'increment the global number
        Me.CreateGraphics.DrawString(Number, MyFont, MyBrush, e.X, e.Y) 'draw the number inside the circle    
    End Sub
End Class

Note: This may not seem like a terribly useful project, but it lays the ground work for drawing graphs and charts on the fly from data retrieved from a file or a database later on.

NEXT: The Brush