Picturebox Help
Posted: Thu Nov 29, 2012 8:53 pm
Hello i am buildling an app that has a picture that you add and then move arround but you can add this image as many times as you like so now i am trying to make it so if you hover over one of the picutres and right click it will get removed i attempted to use this code but it does not work
Code: Select all
Just so you can see how i am adding and using the Pictureboxes here is the full Code for the Relevant part
Private Sub PictureBox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
Dim PB As New PictureBox
sender = Me.Controls.Remove(PB)
End If
End Sub
Code: Select all
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Dim PB As New PictureBox
PB.Size = New Size(50, 50)
PB.SizeMode = PictureBoxSizeMode.StretchImage
PB.Image = PictureBox1.Image
PB.BackColor = Color.Transparent
AddHandler PB.MouseMove, AddressOf PictureBox_MouseMove
AddHandler PB.MouseDown, AddressOf PictureBox_MouseDown
AddHandler PB.MouseUp, AddressOf PictureBox_MouseUp
Panel3.Controls.Add(PB)
cost.Text = (cost.Text + 2.51)
Label11.Text = Label11.Text + 1
End Sub
Private Sub PictureBox_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
P = e.Location
End Sub
Private Sub PictureBox_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
If e.Button = MouseButtons.Left Then
sender.Location = New Point(sender.Location.X + (e.X - P.X), sender.Location.Y + (e.Y - P.Y))
End If
End Sub
Private Sub PictureBox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
Dim PB As New PictureBox
sender = Me.Controls.Remove(PB)
End If
End Sub