How to assign the text to toolstripstatus in runtime?
-
Hello All, I am Savitri Here. I am new to this forum and also to this language. I am doing one application in C#. Now i have two forms called Mainform and LoginForm. After running we login form will come and after successful login will get mainform. I want to assign the entered user name to toolstripstautuslable of statusstrip which is in mainform.When i clicking login button then only i am setting new value for that status strip but it is not assigning. Please help me. Below is the part of code. LoginForm.Cs
MainForm frm = new MainForm(); private void btnLogin_Click(object sender, EventArgs e) { string username,password; username=txtUsr.Text.ToString(); password=txtPwd.Text.ToString(); if(username.Equals("xxxxxx") && password.Equals("xxxxxx")) { MessageBox.Show("SuccessFully Logged in"); frm.toolStripStatusLabel2.Text = txtUsr.Text; frm.GetValues(username, password);//textBox1_TextChanged(); this.Visible=false; } else { MessageBox.Show("Not valid UserName and Password"); } }
MainForm.cspublic void GetValues(string strUsr,string strPwd) { this.UsrNam=strUsr; MessageBox.Show(UsrNam); this.PasPwd=strPwd; MessageBox.Show(PasPwd); this.toolStripStatusLabel2.Text = UsrNam.ToString(); this.Refresh(); }
Please Give me hints. Help me. Thanks in Advance. Regards, Savitri P -
Hello All, I am Savitri Here. I am new to this forum and also to this language. I am doing one application in C#. Now i have two forms called Mainform and LoginForm. After running we login form will come and after successful login will get mainform. I want to assign the entered user name to toolstripstautuslable of statusstrip which is in mainform.When i clicking login button then only i am setting new value for that status strip but it is not assigning. Please help me. Below is the part of code. LoginForm.Cs
MainForm frm = new MainForm(); private void btnLogin_Click(object sender, EventArgs e) { string username,password; username=txtUsr.Text.ToString(); password=txtPwd.Text.ToString(); if(username.Equals("xxxxxx") && password.Equals("xxxxxx")) { MessageBox.Show("SuccessFully Logged in"); frm.toolStripStatusLabel2.Text = txtUsr.Text; frm.GetValues(username, password);//textBox1_TextChanged(); this.Visible=false; } else { MessageBox.Show("Not valid UserName and Password"); } }
MainForm.cspublic void GetValues(string strUsr,string strPwd) { this.UsrNam=strUsr; MessageBox.Show(UsrNam); this.PasPwd=strPwd; MessageBox.Show(PasPwd); this.toolStripStatusLabel2.Text = UsrNam.ToString(); this.Refresh(); }
Please Give me hints. Help me. Thanks in Advance. Regards, Savitri PDoes this line
MessageBox.Show(UsrNam);
show the username?Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Does this line
MessageBox.Show(UsrNam);
show the username?Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Hi Henry, Ya that is user name. I want to display that user name into status strip in main from. Please give me some hints to solve this problem. Thanks in Advance. Regards, Savitri P
Yes, I understand that, but when the MessageBox displays, does it show the username, is it blank, does it display something that you are not expecting?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Yes, I understand that, but when the MessageBox displays, does it show the username, is it blank, does it display something that you are not expecting?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Ya it is displaying username in messagebox but it is not showing in status strip and not refreshing control also. I tried many ways but it is not displaying. Regards, Savitri P
The code you have provided, is over complicated: your code:
public void GetValues(string strUsr,string strPwd)
{
this.UsrNam=strUsr;
MessageBox.Show(UsrNam);
this.PasPwd=strPwd;
MessageBox.Show(PasPwd);
this.toolStripStatusLabel2.Text = UsrNam.ToString();
this.Refresh();
}can be simplified to:
public void GetValues(string strUsr,string strPwd)
{
this.UsrNam=strUsr;
MessageBox.Show(UsrNam);
this.PasPwd=strPwd;
MessageBox.Show(PasPwd);
this.toolStripStatusLabel2.Text = UsrNam;
}other than that I can see no obvious reason that it should not work. As a test that
toolStripStatusLabel2
is working, temporarily replacethis.toolStripStatusLabel2.Text = UsrNam;
withthis.toolStripStatusLabel2.Text = "Is this visible";
. If you can see "Is this visible" when you run the application, then I am at a loss. If however, you cannot see it, then there is something wrong with one of the properties oftoolStripStatusLabel2
possibly the Visible property is set to false, possibly the location or size properties are incorrectly set. It might even be hidden behind another control.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
The code you have provided, is over complicated: your code:
public void GetValues(string strUsr,string strPwd)
{
this.UsrNam=strUsr;
MessageBox.Show(UsrNam);
this.PasPwd=strPwd;
MessageBox.Show(PasPwd);
this.toolStripStatusLabel2.Text = UsrNam.ToString();
this.Refresh();
}can be simplified to:
public void GetValues(string strUsr,string strPwd)
{
this.UsrNam=strUsr;
MessageBox.Show(UsrNam);
this.PasPwd=strPwd;
MessageBox.Show(PasPwd);
this.toolStripStatusLabel2.Text = UsrNam;
}other than that I can see no obvious reason that it should not work. As a test that
toolStripStatusLabel2
is working, temporarily replacethis.toolStripStatusLabel2.Text = UsrNam;
withthis.toolStripStatusLabel2.Text = "Is this visible";
. If you can see "Is this visible" when you run the application, then I am at a loss. If however, you cannot see it, then there is something wrong with one of the properties oftoolStripStatusLabel2
possibly the Visible property is set to false, possibly the location or size properties are incorrectly set. It might even be hidden behind another control.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
My pleasure. Good Luck. :)
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”