Thadeu Fernandes Thadeu Fernandes - 13 days ago 6
C# Question

Enable button C#

I have an user control calling a method on my main form and this method should enable a button (by default this button is disabled) on the same form, but it's not working.

private void button1_Click(object sender, EventArgs e)
{
Form1 fr = new Form1();
fr.login(textBox1.Text, textBox2.Text);
}


And here is my method

public void login(string username, string password)
{
Connect();
sendMessage("LoginAction,Username=" + username + "UserPassword=" + password);
}


Here is where the button is enabled

private void commandInterpreter(string Message)
{
if(Message.Contains("LoginSuccess,") == true)
{
name = Message.Remove(Message.IndexOf("LoginSuccess,Name="), 18);
Bt2En = true;
}
}


Here is where I'm exposing my button properties:

public bool Bt2En
{
get { return button2.Enabled; }
set { button2.Enabled = value; }
}

Answer

I solved my problem doing this, these are my methods from Form1:

public void login()
    {
        Connect();
        Login lg = this.lg;
        string username = lg.Username;
        string password = lg.Password;
        MessageBox.Show(username + "\n" + password);
    }
private void button1_Click(object sender, EventArgs e)
    {
        login();
    }

And this one is from my user control:

public string Username
    {
        get { return textBox1.Text; }
    }
    public string Password
    {
        get { return textBox2.Text; }
    }

Thanks Steve and Bradley Uffner for help and everyone who tried. I'm posting the answer for who has the same problem.