Really Dumb Questions about forms

J

Jack Russell

I thought that I was a reasonable programmer but I am having some very
basic problems with .net

1) In vb3 to vb6 to use another form I said
frmColorTool.Show

What is the correct syntax in vb.net

2) how do I adress the controls in another form

Again I used to say
Form1!control.text

How do I do this now?
 
I

Imran Koradia

Jack,

In VB.NET, forms and controls are objects just like regular objects. So,
you'll need to instantiate the form before you can call Show on the form.
Similarly, you'll need an instance of the form to access the controls of
that form.

Dim frm As New frmColorTool
frm.Show() ' Or frm.ShowDialog() for modal

Debug.Write(frm.txtTextBox.Text)

Note that in VB.NET, since the default access modifier for controls is
Friend, you can access the controls of a form from another form only if both
forms are in the same project.

hope that helps..
Imran.
 
J

Jack Russell

Thanks, that is the way that I am doing it, I just find it hard to
believe that MS seems to have gone backwards!

Imran said:
Jack,

In VB.NET, forms and controls are objects just like regular objects. So,
you'll need to instantiate the form before you can call Show on the form.
Similarly, you'll need an instance of the form to access the controls of
that form.

Dim frm As New frmColorTool
frm.Show() ' Or frm.ShowDialog() for modal

Debug.Write(frm.txtTextBox.Text)

Note that in VB.NET, since the default access modifier for controls is
Friend, you can access the controls of a form from another form only if both
forms are in the same project.

hope that helps..
Imran.
 
R

Ray Cassick \(Home\)

Not backwards, just more accurate.

Older versions of VB held global references to your forms behind the scenes
for you so all you had to do was frmForm.Show or frmForm.Load.

VB.NET requires you to actually create instances of your forms because,
after all, they are really just classes that inherit from type
System.Windows.Forms.Form.

Jack Russell said:
Thanks, that is the way that I am doing it, I just find it hard to
believe that MS seems to have gone backwards!
 

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