I have two forms Login and Main Menu. I want to retrieve the username from the textbox1 from login and put it in the status strip in the main menu. However, when i change the modifier of textbox1 with this code

TextBox textBox1;
  public Login(TextBox txtBox);

or any other code i found to change the modifier of textbox1 i come up with this error in the login form
Error 1 Ambiguity between 'GOGREEN.Login.textBox1' and 'GOGREEN.Login.textBox1'


i even changed it from the properties window but that does not work! please help me out thanks

Recommended Answers

All 2 Replies

1st of all: Do not change your controls (textBox in this case) access modifier. Leave it as private (never change it to public, because this is the worst thing you can do). There ar plenty of other ways to access the control, but directly from inside the class (form) where the control is instantiated. Create a new public method in this form, add a parameter to it, and then call THIS form from some other class to update the control.

And you see what can brings you when changing access modifiers? As said, leave it as private.
Example:

class Login
{
     public void UpdatingTextBox1(string msg)
     {
          textBox1.Text = msg;
     }
}

class Form1:
//inside of your method which calls Login form:
Login l = new Login();
l.UpdatingTextBox1 = "some text to pass".

thanks!! However there were other types of errors when i tried what you said. so i created a variable and made it to public and then called it through the other form it worked well but when you debug it the value does not pass logically so i think i have another problem to solve!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.