Mousedown feature on a Pic Box added via controls.add? {RESOLVED}
Hello,
I have this code here to create a PictureBox when the user clicks a cmd button.
Here is the code:
VB Code:
Private Sub mnuPopCopy_Click()
Dim mobjPicture As PictureBox
If shpCrop.Visible = False Then Exit Sub
Set mobjPicture = Controls.Add("VB.PictureBox", "Pic")
With mobjPicture
.Width = intWidth
.Height = intHeight
.AutoSize = True
.AutoRedraw = True
.Visible = True
.Left = Picture1.Left
.Top = Picture1.Top
End With
mobjPicture.PaintPicture Picture1.Picture, 0, 0, , , intLeft, intTop
Clipboard.Clear
Clipboard.SetData mobjPicture.Image
Picture1.Visible = False
shpCrop.Visible = False
Set mobjPicture = Nothing
End Sub
Now what I need to do is get it so that once this picture box is loaded I want it to have this code.
VB Code:
Private Sub mobjPicture_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MsgBox "YES!"
End Sub
However even with this code, when I click on the new pic box nothing happens.
Does anyone know how to fix that?
Thank you and have a great day! :thumb:
Stilekid007
Re: Mousedown feature on a Pic Box added via controls.add?
Declare your object variable in form's general section (instead of locally) using WithEvents keyword:
VB Code:
Option Explicit
Dim WithEvents mobjPicture As PictureBox
1 Attachment(s)
Re: Mousedown feature on a Pic Box added via controls.add?
Hmm no go. That didn't work either. Nothing happens when I click on the newly created pic box.
Here is the project if you wanna have a look I will rate you!
Thank you so much!
Stilekid007
Re: Mousedown feature on a Pic Box added via controls.add?
Well the project works for me just the way it is :ehh:
Re: Mousedown feature on a Pic Box added via controls.add?
Well, the project did not work for me. The reason, you set the mobjPicture variable to nothing in the mnuPopCopy_Click event. Remove that line of code.
Re: Mousedown feature on a Pic Box added via controls.add?
aaHaaa! Brilliant bruceVB!!!! Your great thank you so much! :thumb:
Thank you all for your responses and help!
Stilekid007 :wave: