The variable 'controlname' is either undeclared or was never assigned.

M

mros

I've created three buttons on a form (IsMdiContainer=True), it's mdi parent.
I need to disable these buttons from one of my child form. So,
I've changed these buttons modifier to Friend Shared WithEvents
'controlname' as System.Windows.Forms.button
and I was able to disable these buttons from my child form.

The problem is when I load the form in the form designer. It gives
me this error: "The variable 'controlname' is either undeclared or was
never assigned."

Anyone? Help...Thanks!
 
C

CJ Taylor

You really really really don't want to declare your controls shared, I don't
even want to think of the consequences with that (because the design of MDI
afterall is many instances of the same child form, i.e. Microsoft Word).

If your MDI Parent is in the same namespace as your MDI Children, then you
should just be able to access them without a problem through the
instantiated class

i.e.

dim myForm1 as new MyForm()

myForm1.buttonOk.Enabled = False
myForm.MdiParent = me
myForm1.Show()

if you still can't access them, try declaring your controls Public. Thats
the modifier property in your property grid.

HTH,
CJ
 
M

mros

True. I don't know what else to do. I've tried your suggested example
before but it created another instance of the program which I don't want
to do. I've also tried changing the access modifier to public and still no
luck.

The buttons are on the parent form and I'm trying to disable them from the
child form. If I create another instance of the parent form, I won't be
accessing
the same buttons for disabling.

I'm curious about the namespace. Right now, every form object has the same
namespace i.e.
-WinMDI Namespace
- <Class Name>
Is that what you mean?

Thanks!
mros
 
C

CJ Taylor

Ahh, ok, I thought they were on the child form.

You can access the parent form in the childfrom by

Ctype(me.MdiParent, myMdiClass)

then set your button to enabled or disabled whatever.
 
H

Herfried K. Wagner [MVP]

* "mros said:
I've created three buttons on a form (IsMdiContainer=True), it's mdi parent.
I need to disable these buttons from one of my child form. So,
I've changed these buttons modifier to Friend Shared WithEvents
'controlname' as System.Windows.Forms.button
and I was able to disable these buttons from my child form.

The problem is when I load the form in the form designer. It gives
me this error: "The variable 'controlname' is either undeclared or was
never assigned."

Don't make the control shared, that doesn't make sense. Controls always
belong to an instance of a form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top