PC Review


Reply
Thread Tools Rate Thread

How to control a label from an external class

 
 
Dr_PoLish (the schnitzel)
Guest
Posts: n/a
 
      24th Dec 2006
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 ?

 
Reply With Quote
 
 
 
 
Angel Caban
Guest
Posts: n/a
 
      25th Dec 2006
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);
}
}
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access control on a page from inside an external class Andy B Microsoft ASP .NET 7 2nd Jun 2008 11:08 AM
Label derived class Allen Bradley Microsoft Dot NET Compact Framework 0 14th Jun 2007 01:11 PM
error LNK2019: unresolved external symbol "public: static class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > danip Microsoft VC .NET 0 5th Dec 2005 10:01 AM
Using an External Control Class =?Utf-8?B?UmVNRW4=?= Microsoft VC .NET 0 17th Mar 2005 10:20 PM
How can I create a split bar control (label control) to resize parts of a form? Savvoulidis Iordanis Microsoft Access Form Coding 7 15th Sep 2004 12:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:21 PM.