' RandomPoints Example ' Show how to use the DrawEllipse method ' to draw random points in the Paint method ' of a picture box. Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents picDisplay As System.Windows.Forms.PictureBox Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents mnuPoints As System.Windows.Forms.MenuItem Friend WithEvents mnu100 As System.Windows.Forms.MenuItem Friend WithEvents mnu1000 As System.Windows.Forms.MenuItem Friend WithEvents mnu10000 As System.Windows.Forms.MenuItem Friend WithEvents mnu100000 As System.Windows.Forms.MenuItem Private Sub InitializeComponent() Me.picDisplay = New System.Windows.Forms.PictureBox Me.MainMenu1 = New System.Windows.Forms.MainMenu Me.mnuPoints = New System.Windows.Forms.MenuItem Me.mnu100 = New System.Windows.Forms.MenuItem Me.mnu1000 = New System.Windows.Forms.MenuItem Me.mnu10000 = New System.Windows.Forms.MenuItem Me.mnu100000 = New System.Windows.Forms.MenuItem Me.SuspendLayout() ' 'picDisplay ' Me.picDisplay.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.picDisplay.Location = New System.Drawing.Point(48, 24) Me.picDisplay.Name = "picDisplay" Me.picDisplay.Size = New System.Drawing.Size(300, 300) Me.picDisplay.TabIndex = 0 Me.picDisplay.TabStop = False ' 'MainMenu1 ' Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuPoints}) ' 'mnuPoints ' Me.mnuPoints.Index = 0 Me.mnuPoints.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnu100, Me.mnu1000, Me.mnu10000, Me.mnu100000}) Me.mnuPoints.Text = "Number of Points" ' 'mnu100 ' Me.mnu100.Index = 0 Me.mnu100.Text = "100" ' 'mnu1000 ' Me.mnu1000.Index = 1 Me.mnu1000.Text = "1000" ' 'mnu10000 ' Me.mnu10000.Index = 2 Me.mnu10000.Text = "10000" ' 'mnu100000 ' Me.mnu100000.Index = 3 Me.mnu100000.Text = "100000" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(392, 350) Me.Controls.Add(Me.picDisplay) Me.Menu = Me.MainMenu1 Me.Name = "Form1" Me.Text = "RandomPoints" Me.ResumeLayout(False) End Sub #End Region Dim n As Integer = 100 Dim rad As Integer = 4 Private Sub picDisplay_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) _ Handles picDisplay.Paint Dim i, x, y As Integer Dim r As New Random Dim b As New SolidBrush(Color.Red) Dim g As Graphics = e.Graphics For i = 1 To n x = r.Next(0, 300) y = r.Next(0, 300) g.FillEllipse(b, x - rad, y - rad, rad, rad) Next End Sub Private Sub mnu100_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles mnu100.Click n = 100 rad = 4 picDisplay.Invalidate() End Sub Private Sub mnu1000_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles mnu1000.Click n = 1000 rad = 3 picDisplay.Invalidate() End Sub Private Sub mnu10000_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles mnu10000.Click n = 10000 rad = 2 picDisplay.Invalidate() End Sub Private Sub mnu100000_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles mnu100000.Click n = 100000 rad = 2 picDisplay.Invalidate() End Sub End Class