help with picturebox in vb on VS2005

trashkan

New member
Joined
Dec 21, 2009
Messages
4
Programming Experience
3-5
if i add a picturebox in design then add an image who is triangle formed and make background transparent in setting on the picturebox how do i then make an click event on the picturebox.image? iwant nothing happen if i click on the picturebox background only the image!!

help me out.. thx
 
I would do this:

VB.NET:
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Dim MousePos As Point = PictureBox1.PointToClient(MousePosition)
        If PictureBox1.Image IsNot Nothing AndAlso _
           MousePos.X < PictureBox1.Image.Width And _
           MousePos.Y < PictureBox1.Image.Height AndAlso _
           CType(PictureBox1.Image, Bitmap).GetPixel(MousePos.X, MousePos.Y).A > 0 Then
            'Run your code here
        End If
    End Sub
 
ok i fixed the mousepos to mouseposition and the debugger dont get any error.

still have problems.. when i click on the image nothing happends i add a messagebox where you said add i should add code

any clue?

VB.NET:
Public Class Form1

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        If PictureBox2.Image IsNot Nothing AndAlso _
   MousePosition.X < PictureBox2.Image.Width And _
   MousePosition.Y < PictureBox2.Image.Height AndAlso _
   CType(PictureBox2.Image, Bitmap).GetPixel(MousePosition.X, MousePosition.Y).A > 0 Then
            'Run your code here

            MessageBox.Show("hello world")
        End If



    End Sub

End Class
 
this one worked but now i have a new problem!!

iwant MessageBox.Show("Image Clicked") not be able to show if i click on the image transparent background
VB.NET:
    Private Sub PictureBox2_MouseDown1(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox2.MouseDown
        If e.X >= 0 AndAlso e.X <= PictureBox2.Image.Width AndAlso e.Y >= 0 AndAlso e.Y <= PictureBox2.Image.Height Then

            MessageBox.Show("Image Clicked")
        End If
    End Sub
 
Back
Top