473,383 Members | 1,863 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,383 software developers and data experts.

Controlling Form 1 label from a seperate class file???

Hi all,

I posted this yesterday but didnt explain it too well so thought I would do
it again.

I have a label on a form that I want to be able to change the text while I'm
in a seperate class file. For example -

FORM1 IS :

nsInterface
{
clsInterface
{
private System.Windows.Forms.Label lblStatus;

public void setStatus(text)
{
lblStatus.Text = text;
}
}
}

THE SEPERATE CLASS FILE IS :

nsConvert
{
clsConvert
{
public void convertNow()
{
nsInterface.clsInterface objInterface = new
nsInterface.clsInterface();

objInterface.setStatus("hello world");
}
}
}

I intend the Form1 (which is called frmInterface) lblStatus control to show
the text which is passed to it from the convertNow method which is in a
seperate class file. So to repeat all I want to do is have the From1
(frmInterface) lblStatus control show the text which is passed to it.

Hope this makes sense. Thanks in advance.
--
Message posted via http://www.dotnetmonster.com
Nov 17 '05 #1
7 2380
I should add that when I compile there are no errors. The method setStatus
(string text) is receiving the correct text but I cant get the lblStatus to
show on the Form1 (frmInterface) while the app is runnning.

I should also add that in my initial post where it has clsInterface it is
actually frmInterface as this is what the form is called.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200511/1
Nov 17 '05 #2
Hi,

what you want to implement is a Observer Pattern.
Try out the following.

interface ISetStatus
{
void SetStatus(string status);
}

class form1 : System.Windows.Forms.Form, ISetStatus
{
public form1()
{
MyCallerClass myc = new MyCallerClass((ISetStatus)this);
}

void SetStatus(string status)
{
this.lable1.Text = status;
}
}

class MyCallerClass
{
private ISetStatus _obISetStatus;

public MyCallerClass(ISetStatus oISetStatus)
{
this._obISetStatus = oISetStatus;
this._ObIStetStatus.SetStatus("Hello");
}
}

Hope that helps. You also can use event for such
things ;)

Cheers
Lars Behrmann

Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/
Jon S via DotNetMonster.com schrieb:
Hi all,

I posted this yesterday but didnt explain it too well so thought I would do
it again.

I have a label on a form that I want to be able to change the text while I'm
in a seperate class file. For example -

FORM1 IS :

nsInterface
{
clsInterface
{
private System.Windows.Forms.Label lblStatus;

public void setStatus(text)
{
lblStatus.Text = text;
}
}
}

THE SEPERATE CLASS FILE IS :

nsConvert
{
clsConvert
{
public void convertNow()
{
nsInterface.clsInterface objInterface = new
nsInterface.clsInterface();

objInterface.setStatus("hello world");
}
}
}

I intend the Form1 (which is called frmInterface) lblStatus control to show
the text which is passed to it from the convertNow method which is in a
seperate class file. So to repeat all I want to do is have the From1
(frmInterface) lblStatus control show the text which is passed to it.

Hope this makes sense. Thanks in advance.
--
Message posted via http://www.dotnetmonster.com


Nov 17 '05 #3
Hi,

If I got you right you would like to "elegantly" change the contents of a
label on a form defined in a different file?

Situation:
FormA is a form in FileA
FormB is a form in FileB
FormB is supposed to be able to alter the contents of a label on a FormA
window.

Remember, FormA annd Form B are CLASSES! with new FormA() or new FormB() you
can create instances of those classes/windows.

If an INSTANCE of FormB is to reference an INSTANCE of FormA it needs a
REFERENCE!

Solution

FormA.cs
namespace GetItRight {
public class FormA : System.Windows.Form {
private System.Windows.Forms.Label Label1 = null;
public FormA() {
// the usual stuff
}
public void Foo() { // here we create and display a FormB window giving
it a reference to our Label1!
using(FormB frmB = new FormB()) {
frmB.ExternalLabel = this.Label1;
frm.ShowDialog();
}
}
}
}

FormB.cs
namspace GetItRight {
public class FormB : System.Windows.Form {
private System.Window.Forms.Label mExternalLabel = null;
public FormB() {
// the usual stuff
}
// here we define an "elegant" solution for outsiders to reference my
label
public System.Windows.Forms.Label ExternalLabel {
get { return mExternalLabel; }
set { mExternalLabel = value; }
}
public Foo () { // here I change the Text-Value of ExternalLabel
situated "somewhere"
ExternalLabel.Text = "I changed you on a FormA-Window!";
}
}
}
"Jon S via DotNetMonster.com" <u2272@uwe> schrieb im Newsbeitrag
news:56b4bbf2e3ac6@uwe...
I should add that when I compile there are no errors. The method setStatus
(string text) is receiving the correct text but I cant get the lblStatus
to
show on the Form1 (frmInterface) while the app is runnning.

I should also add that in my initial post where it has clsInterface it is
actually frmInterface as this is what the form is called.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200511/1

Nov 17 '05 #4
Hey Lars and Robert

Thanks for replying. I dont think the problem is with referencing the
lblStatus. The lblStatus is getting the text but its not showing on the
frmInterface. The lblStatus control has properties to show the label but for
some reason when it runs it doesnt show even though the form that the
lblStatus resides on is showing. Do I need to add some code in order for it
to show the lblStatus. I now have the following code :

nsInterface
{
public class frmInterface
{
public void setStatus(string text)
{
this.lblStatus.Text = text;
}
}
}

nsConvert
{
public class clsConvert
{
public void convertNow()
{
nsInterface.frmInterface objInterface = new nsInterface.
frmInterface();
objInterface.setStatus("hello world");
}
}
}
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200511/1
Nov 17 '05 #5
if the prefixes ns, frm, cls refer to namespace, Form, Class then
in setStatus you might (under certain circumstances) need to call
this.lblStatus.Refresh() or this.Refresh()

"Jon S via DotNetMonster.com" <u2272@uwe> schrieb im Newsbeitrag
news:56b5607bcfabe@uwe...
Hey Lars and Robert

Thanks for replying. I dont think the problem is with referencing the
lblStatus. The lblStatus is getting the text but its not showing on the
frmInterface. The lblStatus control has properties to show the label but
for
some reason when it runs it doesnt show even though the form that the
lblStatus resides on is showing. Do I need to add some code in order for
it
to show the lblStatus. I now have the following code :

nsInterface
{
public class frmInterface
{
public void setStatus(string text)
{
this.lblStatus.Text = text;
}
}
}

nsConvert
{
public class clsConvert
{
public void convertNow()
{
nsInterface.frmInterface objInterface = new nsInterface.
frmInterface();
objInterface.setStatus("hello world");
}
}
}
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200511/1

Nov 17 '05 #6
Hi,

if it is a repaint problem? Then try to call
the Refresh() method on the control after
you call setStatus. It will force to paint it
self and all his child controls new.

Cheers
Lars Behrmann

Jon S via DotNetMonster.com schrieb:
Hey Lars and Robert

Thanks for replying. I dont think the problem is with referencing the
lblStatus. The lblStatus is getting the text but its not showing on the
frmInterface. The lblStatus control has properties to show the label but for
some reason when it runs it doesnt show even though the form that the
lblStatus resides on is showing. Do I need to add some code in order for it
to show the lblStatus. I now have the following code :

nsInterface
{
public class frmInterface
{
public void setStatus(string text)
{
this.lblStatus.Text = text;
}
}
}

nsConvert
{
public class clsConvert
{
public void convertNow()
{
nsInterface.frmInterface objInterface = new nsInterface.
frmInterface();
objInterface.setStatus("hello world");
}
}
}
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200511/1


Nov 17 '05 #7
Hi guys,

Yes, you're both abosolutely right the refresh() method works.

Thanks.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200511/1
Nov 17 '05 #8

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

Similar topics

16
by: David Lauberts | last post by:
Hi Wonder if someone has some words of wisdom. I have a access 2002 form that contains 2 graph objects that overlay each other and would like to export them as a JPEG to use in a presentation....
0
by: Giulio Santorini | last post by:
Hi, I've got two drop down list controls. When I select a value from the first one I fill the second one. And when I select a value from the second one I would like to fill another control. But...
2
by: DaWoE | last post by:
Hi all, I'm fairly new to ASP.NET. What i want to do is creat a online registration form. On the first step is getting the users details and the number of people he wants to register. Based on...
0
by: Benjamin Bittner | last post by:
Hallo NG, ive searched a lot in some google groups, and found many threads, but nothing that helped me. Here is the scenario: I have an aspx page which loads a user control in page.onInit like...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
2
by: Dick Swager | last post by:
I have a form with a progress bar and a label. The form launches a class that raises an event to indicate the progress. The event arguments contains integers to update the progress bar and a...
11
by: oliver.saunders | last post by:
I'm looking for help with project. I have written a detailed post about it. Please see: http://forums.devnetwork.net/viewtopic.php?t=52753
5
by: kevinmajor1 | last post by:
Hello, all. I'm currently trying to write a script that will perform form validation upon submission. I know that more validation should be performed on the server's side...this is just a test to...
3
by: jerry101 | last post by:
Okay, so I have no knowledge with ASP and I was asked to look at this contact form because the emails aren't delivering. I'll post the whole page of code, because I am unsure at what is what...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.