473,406 Members | 2,707 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 Textbox from Outside Class

I am having trouble updating the text in a C# form textbox from outside the
class. Calling function ChangeDisplay from inside the class ControlPanel
works fine, but when I call it from the main program, it doesn't update. I
have declared the variable in another class called global vars, which
several other classes are using.

namespace ControlPanel

{

public class Form1 : System.Windows.Forms.Form

private System.Windows.Forms.TextBox cp_screen;

private System.ComponentModel.Container components = null;

public string keypadinput = "";
public Form1()

{

InitializeComponent();

}

public void ChangeDisplay(string x) // Set display to the passed string

{

cp_screen.Text= x;

}

------------Class Declaration------------------------------

namespace globalvars

{

public class variables

{

public static Form1 Controlpannel = new Form1(); // Start a new instance of
the control pannel class

public static Controller MainController = new Controller(); // Initialize
the main system controller

}

}

Thanks,

Kevin Bowser

Nov 16 '05 #1
3 2952
Hi Kevin,

How do you launch your program? (What does Main() look like?)
How do you launch ControlPanel/MainForm and communicate with them?

Happy Coding!
Morten Wennevik [C# MVP]
"Kevin Bowser" <ke*******@comcast.net> skrev i melding
news:DJakd.386937$D%.64951@attbi_s51...
I am having trouble updating the text in a C# form textbox from outside the
class. Calling function ChangeDisplay from inside the class ControlPanel
works fine, but when I call it from the main program, it doesn't update.
I
have declared the variable in another class called global vars, which
several other classes are using.

namespace ControlPanel

{

public class Form1 : System.Windows.Forms.Form

private System.Windows.Forms.TextBox cp_screen;

private System.ComponentModel.Container components = null;

public string keypadinput = "";
public Form1()

{

InitializeComponent();

}

public void ChangeDisplay(string x) // Set display to the passed string

{

cp_screen.Text= x;

}

------------Class Declaration------------------------------

namespace globalvars

{

public class variables

{

public static Form1 Controlpannel = new Form1(); // Start a new instance
of
the control pannel class

public static Controller MainController = new Controller(); // Initialize
the main system controller

}

}

Thanks,

Kevin Bowser


Nov 16 '05 #2
Hi Kevin,

How do you launch your program? (What does Main() look like?)
How do you launch ControlPanel/MainForm and communicate with them?

Happy Coding!
Morten Wennevik [C# MVP]
"Kevin Bowser" <ke*******@comcast.net> skrev i melding
news:DJakd.386937$D%.64951@attbi_s51...
I am having trouble updating the text in a C# form textbox from outside the
class. Calling function ChangeDisplay from inside the class ControlPanel
works fine, but when I call it from the main program, it doesn't update.
I
have declared the variable in another class called global vars, which
several other classes are using.

namespace ControlPanel

{

public class Form1 : System.Windows.Forms.Form

private System.Windows.Forms.TextBox cp_screen;

private System.ComponentModel.Container components = null;

public string keypadinput = "";
public Form1()

{

InitializeComponent();

}

public void ChangeDisplay(string x) // Set display to the passed string

{

cp_screen.Text= x;

}

------------Class Declaration------------------------------

namespace globalvars

{

public class variables

{

public static Form1 Controlpannel = new Form1(); // Start a new instance
of
the control pannel class

public static Controller MainController = new Controller(); // Initialize
the main system controller

}

}

Thanks,

Kevin Bowser


Nov 16 '05 #3
I appologize, what I was trying to make the program do is not possible.

The apps are event driven, and you can not update the display without an
event. So I just have a timer that checks to see if the display needs to be
changes every 30 seconds. Quick workaround for the security system
simulator I am trying to put together.
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl...
Hi Kevin,

How do you launch your program? (What does Main() look like?)
How do you launch ControlPanel/MainForm and communicate with them?

Happy Coding!
Morten Wennevik [C# MVP]
"Kevin Bowser" <ke*******@comcast.net> skrev i melding
news:DJakd.386937$D%.64951@attbi_s51...
I am having trouble updating the text in a C# form textbox from outside
the
class. Calling function ChangeDisplay from inside the class ControlPanel
works fine, but when I call it from the main program, it doesn't update.
I
have declared the variable in another class called global vars, which
several other classes are using.

namespace ControlPanel

{

public class Form1 : System.Windows.Forms.Form

private System.Windows.Forms.TextBox cp_screen;

private System.ComponentModel.Container components = null;

public string keypadinput = "";
public Form1()

{

InitializeComponent();

}

public void ChangeDisplay(string x) // Set display to the passed string

{

cp_screen.Text= x;

}

------------Class Declaration------------------------------

namespace globalvars

{

public class variables

{

public static Form1 Controlpannel = new Form1(); // Start a new instance
of
the control pannel class

public static Controller MainController = new Controller(); // Initialize
the main system controller

}

}

Thanks,

Kevin Bowser



Nov 16 '05 #4

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

Similar topics

0
by: Kevin Bowser | last post by:
I am having trouble updating the text in a C# form textbox from outside the class. Calling function ChangeDisplay from inside the class ControlPanel works fine, but when I call it from the main...
28
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
9
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control,...
3
by: Tom | last post by:
I am writing a Visual basic .Net database application. There are many forms that first let you select and look at a DB record and then when you click a "modify" button you are allowed to change...
9
by: Aaron Smith | last post by:
I am creating a subclassed text box. I want to have a button inside the tetbox. That was the easy part. The part I can't figure out, is how you set the area for the text? If you type a string it...
3
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. ...
2
by: Walter | last post by:
I have a GridView using Template columns. In my EditItemTemplate I am using CompareValidators to check data types. When validation fails, I would like to change the border of the textbox in...
0
by: zeng.hui.stephen | last post by:
I download the demo http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/. I inherite the demo, and write my code. I want to use Hook to monitor C++ Edit change. I use a C# form...
4
by: Dean Slindee | last post by:
Anyone got a quick and easy way to change the background color on a textbox after the user has change the text value. Already have lots of forms written, so an approach that does not depend on...
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: 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
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...
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,...
0
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...

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.