Public Class Form1 Dim PenColor As New Pen(Color.Red, 2) Dim X As Long Dim Y As Long Dim W As Long Dim H As Long Dim NewFlag As Boolean ' The Bitmap and Graphics objects we will draw on. Private m_Bitmap As Bitmap Private m_Graphics As Graphics ' Make the initial blank image. Private Sub Form1_Load() Handles MyBase.Load NewFlag = True Call MakeNewBitmap() End Sub ' Make a new blank image. Private Sub mnuFileClear_Click() Handles mnuFileClear.Click Call MakeNewBitmap() Panel1.Visible = True 'There are actually 20 Panels but I removed the code to make it more compact for the question End Sub ' Make a new Bitmap to fit the canvas. Private Sub MakeNewBitmap() ' Get the drawing surface's size. Dim wid As Integer = picCanvas.ClientSize.Width Dim hgt As Integer = picCanvas.ClientSize.Height ' Make a Bitmap and Graphics to fit. m_Bitmap = New Bitmap(wid, hgt) m_Graphics = Graphics.FromImage(m_Bitmap) ' Clear the drawing area. m_Graphics.Clear(Me.BackColor) ' Display the result. picCanvas.Image = m_Bitmap End Sub Private Sub MakeGraphics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MakeGraphics.Click NewFlag = True Make some random elipses on screen when button is clicked m_Graphics = Graphics.FromImage(m_Bitmap) For Temp = 1 To 25 Randomize() X = 5 + (Rnd() * (m_Bitmap.Width - 30)) Y = 5 + (Rnd() * (m_Bitmap.Height - 30)) 'Minimum length,width = 20, max = 220 H = 2 + (Rnd() * 20) W = 2 + (Rnd() * 20) m_Graphics.DrawEllipse(PenColor, X, Y, W, H) Next End Sub Private Sub picCanvas_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picCanvas.Paint m_Graphics = Graphics.FromImage(m_Bitmap) End Sub Private Sub HidePanel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HidePanel.Click Dim R As Integer Randomize() R = 1 + Rnd() * 20 Label1.Text = R If R = 1 Then Panel1.Visible = False 'There are actually 20 Panels but I removed the code to make it more compact for the question End Sub End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)