469,293 Members | 1,319 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,293 developers. It's quick & easy.

Change label text on another form

I'm trying to change the text in a label from another form.

lblInfo.Text = "ABC"

Works for the form your currently in but how the heck do you change that
label information from another form.

Later

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
6 8637
Use a property or pass the form with the label you want to change to the
form where you want to change it from

for example call the form used to change the label from the form with the
label:
'First give the second form a new constructor + a var to hold the form
that's passed:

Private Caller As Form1
Public Sub New(ByVal myCaller As Form)
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Caller = DirectCast(myCaller, Form1)
End Sub

'Then in the form with label pass the form to the second forms' constructor
dim obj as new frmUsedToChange(me)
obj.show
'in the second form to change the label
Caller.Label1.Text = "I'm freaking changed ;-)"

hth Peter


"Roger Ries via DotNetMonster.com" <fo***@DotNetMonster.com> schreef in
bericht news:1a******************************@DotNetMonste r.com...
I'm trying to change the text in a label from another form.

lblInfo.Text = "ABC"

Works for the form your currently in but how the heck do you change that
label information from another form.

Later

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #2
Use a property or pass the form with the label you want to change to the
form where you want to change it from

for example call the form used to change the label from the form with the
label:
'First give the second form a new constructor + a var to hold the form
that's passed:

Private Caller As Form1
Public Sub New(ByVal myCaller As Form)
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Caller = DirectCast(myCaller, Form1)
End Sub

'Then in the form with label pass the form to the second forms' constructor
dim obj as new frmUsedToChange(me)
obj.show
'in the second form to change the label
Caller.Label1.Text = "I'm freaking changed ;-)"

hth Peter


"Roger Ries via DotNetMonster.com" <fo***@DotNetMonster.com> schreef in
bericht news:1a******************************@DotNetMonste r.com...
I'm trying to change the text in a label from another form.

lblInfo.Text = "ABC"

Works for the form your currently in but how the heck do you change that
label information from another form.

Later

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #3
I was able to use it and it works.

But what if I wasn't opening frmUsedToChange from Form1?

Say I had opened frmUsedToChange from something else but still needed to
change a label or text box on Form1.

Thanks

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #4
I was able to use it and it works.

But what if I wasn't opening frmUsedToChange from Form1?

Say I had opened frmUsedToChange from something else but still needed to
change a label or text box on Form1.

Thanks

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #5
"Roger Ries via DotNetMonster.com" <fo***@DotNetMonster.com> schrieb:
But what if I wasn't opening frmUsedToChange from Form1?

Say I had opened frmUsedToChange from something else but still needed to
change a label or text box on Form1.


What you need is a reference to your instance of the form you want to
manipulate. There are different ways to make this reference available, for
example, by passing it in method parameters or assigning it to properties,
or implementing the Singleton design pattern if there can be only one
instance of a form:

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
"Roger Ries via DotNetMonster.com" <fo***@DotNetMonster.com> schrieb:
But what if I wasn't opening frmUsedToChange from Form1?

Say I had opened frmUsedToChange from something else but still needed to
change a label or text box on Form1.


What you need is a reference to your instance of the form you want to
manipulate. There are different ways to make this reference available, for
example, by passing it in method parameters or assigning it to properties,
or implementing the Singleton design pattern if there can be only one
instance of a form:

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ken McCrory | last post: by
reply views Thread by Roger Ries via DotNetMonster.com | last post: by
8 posts views Thread by Arpan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.