Sign in to follow this  

User Control VB6 ... QUICK HELP NEEDED!!!

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello... im buildign a user control in VB6. its acutally an icon with diff functions. through a click event on the icon a dialog is opened... my project for the uc consists of a form for the dialog and the actual UC. i would like to access the .Name property of the UC from the codewindow of the dialog. in order to use the .Name of the UC as part of the .Caption of the dialog that pops up... lets say ucPump.Name --> Pump1 in the load form part of the dialog: --> dialog.Caption = "Name of Pumpe" &ucPump.Name ... something like this. im new to VB6 and the tutorials i did didnt provide any info on things like this... so id need some help... THANK YOU

Share this post


Link to post
Share on other sites
This should basically do what you want. It's been a long time since I've done UserControls in VB6, so there's probably a better solution out there someplace, but this ought to do for starters.


' In the dialog form
Dim MyControlReference As TheControl

Public Sub SetControl(ByRef ControlReference As TheControl)
MyControlReference = TheControl
Debug.Print MyControlReference.Name
End Sub


' In the UserControl
Private Sub TheControl_Click()
Dim dialog As TheDialog
dialog = New TheDialog
dialog.SetControl Me.Object
dialog.Show vbModal
dialog = Nothing
End Sub




Basically, the dialog needs to be told what control to "attach" itself to. Once it knows this, it can access it and manipulate it as a normal control. To accomplish this, we simply add a step when we create the dialog, and tell it what control to attach to via our new custom SetControl routine.

Note that SetControl is passed "Me.Object" from the UserControl rather than just Me. This is to ensure that the value given to SetControl is of type TheControl, in case the UserControl is given a default property.

Share this post


Link to post
Share on other sites
It seems to me as if my problem was understood like:

i got a project... import a working user control and add a dialog-form.
then make them work together...


but im still working on the user control...
and withing my usercontrol-project i got code for the usercontrol part and code for the dialog....
and i want to those to work together... the problem is that i cannot call the ucPump in the code window of the dialog... cause withing the project the usercontrol might not be known yet by ucPump...
maybe...
im not sure. thats an assumption...

How can i make them work together?????

Share this post


Link to post
Share on other sites

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this