Dim DrawRectangleGraphics As Graphics
PictureBox.Image = New Bitmap(PictureBox.Width, PictureBox.Height)
DrawRectangleGraphics = System.Drawing.Graphics.FromImage (PictureBox.Image)
DrawRectangleGraphics.Clear(Color.White)
DrawRectangleGraphics.DrawRectangle (Pens.Black, 50, 50, 20, 10)
PictureBox.Refresh()
Private Sub PictureBox_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox.MouseDown
DidYouClickOnTheRectangle(e.X, e.Y, 50, 50, 20, 10)
End Sub
Private Sub DidYouClickOnTheRectangle(ByVal X As Integer, _
ByVal Y As Integer, ByVal SX As Integer, ByVal SY As Integer, _
ByVal SWidth As Integer, ByVal SHeight As Integer)
If X >= SX And X <= SX + SWidth And Y >= SY And Y <= SY + SHeight Then
MsgBox("You Clicked On The Shape☺")
End If
End Sub
Dim TempBitmap As New Bitmap(TheMainPictureBox.Width, TheMainPictureBox.Height)
Dim GraphicsOb As Graphics
GraphicsOb = Graphics.FromImage(TempBitmap)
GraphicsOb.Clear(Color.White)
GraphicsOb.FillRectangle(Brushes.Black,50,50,20,10)
If TempBitmap.GetPixel(e.X, e.Y).ToArgb = -16777216 Then
MessageBox.Show("You Clicked On The Shape !")
End If