Disable and enable buttons in C #

I am working on something quite simple, I thought it would be so. What I want is when button 1 is pressed. I want her to turn off button1 and turn on button2. I get the error below: Error 1 Only the assignment, call, increment, decrement and new object expressions can be used as an operator.

{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button3_Click(object sender, EventArgs e)
    {
        Close();

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    private void RandomNumber(int min, int max)
    {
        int num = new Random().Next(min, max);
         label1.Text = num.ToString();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        RandomNumber(0,99);
        button2.Enabled == true ;
        if (textBox1.Text == label1.Text)
            MessageBox.Show("Winner");

    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {

    } 

}
}
+8
source share
10 answers

In the button1_Click function, you use '==' to button2.Enabled == true;

It should be button2.Enabled = true;

+26
source

button2.Enabled == true ;should be button2.Enabled = true ;.

You have a comparison ==where you should have an appointment =.

+12
source
button2.Enabled == true ;

- :

button2.Enabled = true ;
+5

button2.Enabled == true

button2.Enabled = true;
+5
button2.Enabled == true ;

button2.Enabled = true ;
+4

button2.Enabled == true, button2.Enabled = true. , .

+3

Change button2.Enabled == trueto button2.Enabled = trueand you will be installed!

+2
source

You can use this for your purpose.

In parent form:

private void addCustomerToolStripMenuItem_Click(object sender, EventArgs e)
{
    CustomerPage f = new CustomerPage();
    f.LoadType = 1;
    f.MdiParent = this;
    f.Show();            
    f.Focus();
}

In child form:

public int LoadType{get;set;}

private void CustomerPage_Load(object sender, EventArgs e)
{        
    if (LoadType == 1)
    {
        this.button1.Visible = false;
    }
}
0
source

Update 2019

It is now IsEnabled

 takePicturebutton.IsEnabled = false; // true
0
source

Change this:

button2.Enabled == true;

To:

button2.Enabled = true;
-1
source

All Articles