no1biscuit
Programmer
I have a picturebox that I am trying to drop another picturebox on top of it to cover up sections. Basically like a keymap (You are here) thing. But I want to be able to move the mouse around I want the image to follow cursor to help locate it. Here is my function which doesn't work right. It drops and image where my mouse is then I have to move outside the picturebox and then back in to have it move the floating image. Hopefully this make sense. Here is my code for reference. I documented it as best as I could. (Still vb.net newbie)
Thanks for any insight you have
Thom
Private Sub pctlocator_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pctlocator.MouseMove
On Error GoTo Errorhandler
'c is used to find the existing picturebox
Dim c As PictureBox
'ignore
If insertlocatoricon = True Then
'go out and find the existing little image and delete it
'will cause an error number 9 the first time because it
'does not exist
c = Me.Controls.Find("templocator", True)(0)
Me.Controls.Remove(c)
Dim LocalMousePosition As Point
Dim strx As String
Dim stry As String
Dim locatorid As Integer
Dim sizexy As Integer
LocalMousePosition = Cursor.Position
'Where the XY coords are for little image locator
strx = MousePosition.X
stry = MousePosition.Y
'Currently hard coded 20px x 20px red box image
'that is to be dropped on to the keymap
strlocatorname = "C:\Images\locatoricon\2020.jpg"
Dim pic As PictureBox
Dim cm As New ContextMenuStrip
pic = New PictureBox
Me.SuspendLayout()
strimage = strlocatorname
sizexy = 20
pic.Size = New System.Drawing.Size(sizexy, sizexy)
'for some reason I have to subtract a little to get it to place
'on the map where my cursor is at. If not it puts the little
'image too low on the screen
pic.Location = New System.Drawing.Point(strx - 20, stry - 40)
pic.Image = Image.FromFile(strimage)
pic.Name = "templocator"
'want a right click on the image to delete it in the future
AddHandler cm.Click, AddressOf Me.DeleteClick
cm.Items.Add("Delete " & pic.Name, Nothing, New System.EventHandler(AddressOf DeleteLocatorClick))
Me.Controls.Add(pic)
Me.ResumeLayout()
Me.BringToFront()
End If
Exit Sub
Errorhandler:
If Err.Number = 9 Then
Resume Next
Else
MsgBox("Mouse Move error not captured.")
End If
End Sub
Thanks for any insight you have
Thom
Private Sub pctlocator_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pctlocator.MouseMove
On Error GoTo Errorhandler
'c is used to find the existing picturebox
Dim c As PictureBox
'ignore
If insertlocatoricon = True Then
'go out and find the existing little image and delete it
'will cause an error number 9 the first time because it
'does not exist
c = Me.Controls.Find("templocator", True)(0)
Me.Controls.Remove(c)
Dim LocalMousePosition As Point
Dim strx As String
Dim stry As String
Dim locatorid As Integer
Dim sizexy As Integer
LocalMousePosition = Cursor.Position
'Where the XY coords are for little image locator
strx = MousePosition.X
stry = MousePosition.Y
'Currently hard coded 20px x 20px red box image
'that is to be dropped on to the keymap
strlocatorname = "C:\Images\locatoricon\2020.jpg"
Dim pic As PictureBox
Dim cm As New ContextMenuStrip
pic = New PictureBox
Me.SuspendLayout()
strimage = strlocatorname
sizexy = 20
pic.Size = New System.Drawing.Size(sizexy, sizexy)
'for some reason I have to subtract a little to get it to place
'on the map where my cursor is at. If not it puts the little
'image too low on the screen
pic.Location = New System.Drawing.Point(strx - 20, stry - 40)
pic.Image = Image.FromFile(strimage)
pic.Name = "templocator"
'want a right click on the image to delete it in the future
AddHandler cm.Click, AddressOf Me.DeleteClick
cm.Items.Add("Delete " & pic.Name, Nothing, New System.EventHandler(AddressOf DeleteLocatorClick))
Me.Controls.Add(pic)
Me.ResumeLayout()
Me.BringToFront()
End If
Exit Sub
Errorhandler:
If Err.Number = 9 Then
Resume Next
Else
MsgBox("Mouse Move error not captured.")
End If
End Sub