Changing Label text property on another form

  • Thread starter Thread starter Mike Johnson
  • Start date Start date
M

Mike Johnson

I'm new to VB.Net and programming. I just brought VB.Net Standard I'm
working on a small program for work. I've created two forms the first is
named Forms1 and the second is named SettingsForm on forms1 I've placed two
components a NotifyIcon and FileSystemWatcher. I created a event handler
called onchanged which responds to file being created in a certain
directory. Now my problem is I can't figure out how to change the label.text
property on form two (SettingsForm) from the Event Handler. Can someone
please help me? Thanks in advance.

Also is there other places that might be better suited for Newbees?
 
Hi Mike,

In VB net there are 3 ways of showing a form
A MDI childform
A showdialog
A normal show from a form,

What are you using?

Cor
 
Hello,

You should have (or store) a variable that points to form2, so in your event
"OnChanged", you'd have something like this:

Private m_SettingsForm as SettingsForm

Public Sub OnChanged()

m_SettingsForm.Show()
''' ... etc...

''' this line calls a function on the settings form to update the
label..
m_SettingsForm.UpdateLabel("Text")

End Sub

and in your settings form you'd have the following:

Public Sub UpdateLabel(ByVal LabelText As String)

''' update the label on the settings form
Label1.Text = LabelText

End Sub

HTH
Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:[email protected]
www.callofcthulhu.com www.deadlandsgame.com
-
 
Hi Mike,

* "Mike Johnson said:
I'm new to VB.Net and programming. I just brought VB.Net Standard I'm
working on a small program for work. I've created two forms the first is
named Forms1 and the second is named SettingsForm on forms1 I've placed two
components a NotifyIcon and FileSystemWatcher. I created a event handler
called onchanged which responds to file being created in a certain
directory. Now my problem is I can't figure out how to change the label.text
property on form two (SettingsForm) from the Event Handler.

Have a look here:

<URL:http://www.google.de/[email protected]>

You will have to pass a reference to the form to the other form. In
your case, if you create 'Forms1' from 'SettingsForm', use the code
above. If you create 'SettingsForm' in 'Forms1', you can simply store
the reference to the created form:

\\\
Private m_My2ndForm As SettingsForm
..
..
..
m_My2ndForm = New SettingsForm()
m_My2ndForm.Show()
..
..
..
m_My2ndForm.Label1.Text = "Foo"
///

Feel free to post if you have any questions.
 
Back
Top