How to access a control in another form

  • Thread starter Thread starter Carlos
  • Start date Start date
C

Carlos

In VB6 I was able to accessa control like a progressbar form a different
form, for example

frm1.progressbar1.value =XXX

but now how can I do that in VB.NET

Thanks
 
There is not an 'automatic form collection' in VB.NET.

If the Progress Bar is on Form1, then when you open Form2, it needs to have
a way of finding the Open version of Form1. Just referring to Form1 does
not get a reference to the Open Form1, just to the Form1 class. (You could
have 20 open Form1's in your app)

So, Form2 would have a variable that refers to the open Form1:

Public frmWithProgressBar as Form1


Then to open Form2, Form1 would do:

Dim f as new Form2
f.frmWithProgressBar = Me
f.show


Then Form2 would reference the ProgressBar on the Form1 that opened it as:

me.frmWithProgressBar.NameOfTheProgressBarOnForm1

You could do a property on Form2, but the Public Variable is easier to begin
with.

Kevin
 
* "Carlos said:
In VB6 I was able to accessa control like a progressbar form a different
form, for example

frm1.progressbar1.value =XXX

If 'frm1' is the app's main form, then you can use the approach
described here:

<URL:http://dotnet.mvps.org/dotnet/faqs/downloads/accessmainform.txt>

If the 2nd form is a dialog that is shown from within the main form or
the form containing the progressbar, add a property to the 2nd form and
assign the progressbar to it after instantiating the 2nd form. Then you
will be able to access the progressbar from within the 2nd form.
 
Back
Top