I have two seperate instances of the control on two different forms.
I want to enable certain features on the user control if it is open in form a.
Does this help?
> > I have a User control that is used on two forms.
> >
[quoted text clipped - 7 lines]
> seperate forms, or you have one instance of the control shared between
> the two forms?
> I have two seperate instances of the control on two different forms.
>
> I want to enable certain features on the user control if it is open in form a.
>
> Does this help?
Sorta...
I haven't seen your project so I don't know 100% what you're trying to
do. There's probably a large number of ways you could do this. Also,
are you working in VB 2005, or C#?, or C++?
When you say "enable", so you mean you have UI controls where you want
to say
"someControl.enabled = false"?
Well, in Form A, you could just add code in the FormLoad procedure that
says
"myControl.someFeature.enabled = false"
for every feature you want to have disabled.
If you want to be able to do this through the designer, you can add
properties (I'm gonna assume you're in VB 2005, I don't know if C# has
similar features) to the code of the control itself, such as:
property enableFeatureOne as boolean
Get() as boolean
return Me.featureOne.enabled
End Get
Set (value as boolean)
Me.featureOne.enabled = value
End Set
End property
(It's monday morning so my syntax may be off ;) )
Then you can enable or disable the features right from the design view
of your Form A. (if you do it this way, make sure you rebuild the
project before attempting to use this property in the design view).
hope this helps.
bh - 24 Jul 2006 20:39 GMT
Monday mornings are evil! :)
Im using vb2005.
I have two forms (e.g. form a and form b)with the same user control on both.
The user control contains a host of buttons. I want to be able to open form
a, and press a button and a message box will appear. Whereas if I open form
b and press a button - nothing happens! Make sense? I dont like Mondays at
all :)
I have managed to accomplish this but not in the best way ... I have put a
text box on both forms assigning the value 1 and 0. In the code on the user
control button I have put an if statement on the Click button procedure that
read
If forma.textbox.text=1 then
msgbox("Message")
Endif
I think the following if statement would be appropiate in the user control
if form a is active then
msgbox("message")
Hope you can help?
> > I have two seperate instances of the control on two different forms.
> >
[quoted text clipped - 31 lines]
> project before attempting to use this property in the design view).
> hope this helps.
lord.zoltar@gmail.com - 24 Jul 2006 22:31 GMT
> I have two forms (e.g. form a and form b)with the same user control on both.
> The user control contains a host of buttons. I want to be able to open form
[quoted text clipped - 11 lines]
>
> Endif
Ugh... ugly way to do it. I can think of at least 2 other ways...
Put a private member in the code of each class. Something like this...
Public class formB
inherits Windows.System.Forms.Form
Private buttonsAreActive as boolean = false
...
and in the other form:
Public class formA
inherits Windows.System.Forms.Form
Private buttonsAreActive as boolean = true
Then, you can change your code to look like this:
'In FormA:
if buttonsAreActive then
'Do stuff for active buttons
end if
'in Form B:
if buttonsAreActive then
'Do stuff, but it will never happen because in FormB you set
buttonsAreActive to
'False!
end if
You could also do it by putting the "buttonsAreActive" in the control
as a property, and adding the behaviour when you click on them to the
control (the way I would prefer to do it).