473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 9123
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: beanweed | last post by:
BACKGROUND ---------- I have an ASP.NET application having two panels. In one panel, an XML document, transformed using xsl, is displayed. In the other panel are some controls that allow a user...
3
by: Ken McCrory | last post by:
I have a web form page (.aspx) with 95 label controls that I now need to be text boxes. Is there an easy way to change those to what I want using something like a find and replace or am I stuck...
1
by: nospamjac | last post by:
Hi, Is there a way to update the text of an asp:label on a webform without refreshing the entire page? What is called by button clicks and other events that refresh a webform control? See the...
0
by: Roger Ries via DotNetMonster.com | last post by:
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. ...
5
by: Luis Ramos | last post by:
Hello, How do i change a label in another form from another one? in vb6 i use to do this: form1: private sub label1_change() form2.label1.caption="hgghjghjg" ' and the label in form2 is...
4
by: darnnews | last post by:
When a user selects a "Medium" in a form I have made, I would like to change a Label on the form. Can I change a label based on an update of a listbox? This code does not work: Case "Print"...
8
by: Arpan | last post by:
Consider the following code snippet (my main intention is to display the current time in a Label control as & when this ASPX page is accessed/refreshed): <script runat="server"> Class Clock...
10
by: apparker | last post by:
I'm creating a new GUI for a program and it is for a medical exam. There are so many different things to ask someone during a history it wastes too much space to make checkboxes for everything so I...
2
RedSunFlowers32
by: RedSunFlowers32 | last post by:
Hi - I am creating a form for my personal business site. I want people to be able to get their own shipping total for the item(s) they have purchased. I have another code from a different file I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.