I'm trying to create a control to handle properties and stuff for an image on a user control (I'm essentially turning the image into the button and storing data in the class).
Well I want to pass the actual image control to the class so I can set the properties of the class.
This works fine.. I can do like imgBox.visible from within the class just fine.
The problem is I cannot handle the events of the image anywhere... If I delcare the imgBox variable withevents in the class then it tells me the object isn't declared when I try to pass the image control to it. If I don't use events in the class the control itself dosn't catch it's own events.
It's actually a control array on the usercontrol and all the indexes that I don't pass to the class still handle properly, but the ones that I pass to the class control do not fire their MouseMove Down and Up events that I need...
Any ideas?
EDIT:
Oh I did try another way to, I thought about trying to scratch passing the image and just create one from within the class.. but that didn't work either. I couldn't find anyway to create a dynamic image control on the usercontrol from within the class.
Last edited by StevenHickerson; Sep 14th, 2005 at 01:01 PM.
In the class module declare an image variables with the WithEvents keyword.
VB Code:
Dim WithEvents MyImage As Image
So you will be able to set all events of MyImage.
Then somewhere in teh code set it to your desired image control.
VB Code:
Set MyImage = Form1.Image1
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
As I said I tried that.. the name of my control is TitleBar... I've tried in the class setting it with Set imgBox = TitleBar.Image1 I've tried UserControl.xxx but it will not let me access these outside sources from within the class. Tells me user type variable not defined. And if I try passing the image through a sub it tells me Object not declared on my image.
Last edited by StevenHickerson; Sep 14th, 2005 at 01:29 PM.
Well bpd..that may work but your not set up the same as me.
Se I have a usercontrol.. the class is part of the usercontrol not part of the project.
I'm trying to keep the handling of the image and all out of sight from the form that the usercontrol is placed on. Essentially what I want to be able to do for example is this
VB Code:
'User Control
Public c As New Class1
Private Sub Class_Initialize()
Load imgArray(1)
c.setImg = imgArray(1)
End Sub
VB Code:
'Class code
Public ImgBox As Image
Public Property Let Visible(vSet As Boolean)
imgBox.Visible = vSet
End Property
Friend Property Let setImg(imgSet As Image)
Set imgBox = imgSet
End Property
VB Code:
'Form Code
Private Sub Form_Load()
UserControl1.C.Visible = True
End Sub
Now I can get this much to work.. it's just when I try to handle the events.. they do not get fired anywhere.. not even on the UserControl, it's as if I've done something to cause the image to be eventless.
I think I understand... You want to catch events from a dynamically loaded control array. I don't think you can do that. But you can catch events from dynamically created controls - so long as they're not part of a control array.
VB Code:
Private Sub UserControl_Initialize()
'Load imgArray(1)
Set c.setImg = Controls.Add("VB.Image", "imgArray1")
End Sub
And to "fake" a control array, you can use something like:
VB Code:
Private Property Get imgArray(ByVal Index As Integer) As Image
I even tried something simliar to that bpd.. and it dosn't work because the class cannot see Controls()... says Sub or Function not defined and highlights the word Controls when I try something like that.
I even tried something simliar to that bpd.. and it dosn't work because the class cannot see Controls()... says Sub or Function not defined and highlights the word Controls when I try something like that.
Are you saying the the control creation happens within the Class and not the UserControl?
If you want the controls created by the Class, you'll have to either pass a reference of the UserControl into the class (to gain access to UserControl.Controls) or have the Class call a public method of the UserControl to do the actual control creation.
Ok I've decided to upload my entire project so maybe someone can look at it and figure out what Im doing wrong or at least figure out what I'm trying to do and suggest a better way to do it that works.
So I guess no one can figure this out? See 3 people downloaded the project but no more replies.. I'm just stuck on this project until I can figure this out because I have to have some way of changing the imgbox when the settings are changed and some way of changing the image on mouseevents to do this like I wanted...
The problem is I cannot handle the events of the image anywhere...
In the UserControl_Initialize event, the Label is resized to the size of the entire user control. Since the Label has a higher Z-Order than the Image control it is getting all the mouse events. After loading a new image control make sure its z-order is higher than the label control.
Add this line at the end of the UserControl_Initialize event.
Now the problem I'mhaving though is since I have the label set to transparent and at the back, I was using it to detect when the mouse wasn't on the button, but it will only register if I pass the mouse over some text on the label if its transparent, and the form does not receive the mouse events even though the label is transparent.
So now my problem is detecting when the mouse moves off the image ... lol
bleh, forgot I had the control set to transparent lol.. didn't even realize that setting was there. But it's corrected now. Thanks brucevde, now I can continue the project