By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,673 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,673 IT Pros & Developers. It's quick & easy.

Am I doing something wrong? (Variables)

P: n/a
Hiya all,

I am developing a windows form application. I am coding in C#. What I have
is two forms/Classes, frmMain & frmAdd. In frmMain I have initialize &
instantiated my variable as "public string userName", where I have inputted
a user name. I am trying to get at this data from my frmMain to my frmAdd. I
thought this is the correct syntex for outputting the info in my textbox
(scratching my head), maybe it's not. So please let me know if you can help
or where I'm going wrong. Code is as follows:

namespace Q.A._Testing_Centre
{
public class frmMain : System.Windows.Forms.Form
{
public string userName; <<<---- I want the data from here
....
....
....
namespace Q.A._Testing_Centre
{
public class frmAdd : System.Windows.Forms.Form
{
private void SubMainMenu()
{
frmAdd Main = new frmMain();
txtBoxSample.Text = Convert.ToString(Main.userName);<<<--- to output in my
textbox here
....
....
....
Or maybe if someone has a better alternative, please feel free to let me
know. All help is truly appreciated & thank you all in advance.

MikeY
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Take a look to some fix....
namespace Q.A._Testing_Centre
{
public class frmMain : System.Windows.Forms.Form
{
public static string userName;
//public string userName;

namespace Q.A._Testing_Centre
{
public class frmAdd : System.Windows.Forms.Form
{
private void SubMainMenu()
{
//you don't need this..
// frmMain Main = new frmMain();

//just do this...
txtBoxSample.Text = Convert.ToStrin(frmMain.userName);
}
}
}

You can have access to the frmMain userName field in
that way due to this field is set to be "static", and you
can have access to it wherever you want...

I hope this help.....
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.