472,370 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,370 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 8943
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.