473,508 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to control a label from an external class

I want to be able to control a label from an external class - i tried
to put in a 'private void LabelChange(string Text2Change2) {
label1.Text = Text2Change2 }' into my FrmMain class, and the only way i
can get it working in another class is by

class ExternalClassThing
{
public void ChangeThatLabel(string Text2Change2)
{
FrmMain mainfrm = new FrmMain();
mainfrm.Show();
mainfrm.LabelChange(Text2Change2);
}
}

quite obviously, i cant have a new window pop up each time i want to
change the label's text, so is there any way for the ExternalClassThing
to take control of the current instance of FrmMain ? and maybe even
directly use the label1 ?

Dec 24 '06 #1
1 1750
Dr_PoLish (the schnitzel) wrote:
I want to be able to control a label from an external class - i tried
to put in a 'private void LabelChange(string Text2Change2) {
label1.Text = Text2Change2 }' into my FrmMain class, and the only way i
can get it working in another class is by

class ExternalClassThing
{
public void ChangeThatLabel(string Text2Change2)
{
FrmMain mainfrm = new FrmMain();
mainfrm.Show();
mainfrm.LabelChange(Text2Change2);
}
}

quite obviously, i cant have a new window pop up each time i want to
change the label's text, so is there any way for the ExternalClassThing
to take control of the current instance of FrmMain ? and maybe even
directly use the label1 ?
_if non-static_ then use:
class ExternalClassThing
{
private FrmMain mainfrm;

public ExternalClassThing(FrmMain mainfrm)
{
this.mainfrm = mainfrm;
}

public void ChangeThatLabel(string Text2Change2)
{
mainfrm.LabelChange(Text2Change2);
}
}

_if static_ then use:
class ExternalClassThing
{
public static FrmMain mainfrm;
public static void ChangeThatLabel(string Text2Change2)
{
mainfrm.LabelChange(Text2Change2);
}
}
Dec 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2280
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
6
12261
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
5
3565
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
31
7151
by: jcrouse | last post by:
Is there a quick and easy way to change the color of a label controls border from the default black to white? Thank you, John
0
2449
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
6
1404
by: dana lees | last post by:
Hello, I am developing a c# asp.net application. I have 2 forms. In the first webform ('header') i have a label. I want to reference that label from a different form ('user'), in order to...
8
1912
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...
2
4804
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
1
5095
by: John Dinning | last post by:
(Using VS2005 C# and compact Framework. Target device is running CE5). I am creating a simple visual control (New Control Library project for smart device Windows CE 5), derived from Label, with...
0
7229
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
7398
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...
1
7061
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
5637
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,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.