Referencing Controls by Name in WinForms VB.NET

  • Thread starter Thread starter Steve Floyd
  • Start date Start date
S

Steve Floyd

This is a WinForms question. In the VB6 world, you could
easily reference a control by name, e.g., if I want to
make the check box named chkFlag visible, I would do
this: frmMain.chkFlag.Visible = True.

In VB.NET, what is the proper way to reference controls
by name? frmMain.chkFlag does not work. chkFlag is in the
control collection of frmMain, so I could write a
generalized routine to recursively look thru the control
collections, but thats way too expensive.
 
You should have to refer an instance of the frmMain in the memory. in vb.net
when we create frmmain form through IDE. we are just creating the class, not
any object.

so you can do like,

dim d as new frmmain
d.chkflag.visible = true
d.show()


Rajesh Patel
 
Back
Top