10

I am working on something fairly simple, well I thought it would be. What I want is when button1 is clicked I want it to disable button1 and enable button2. I get the error below: Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement.

private readonly Process proc = new Process();
    public Form1()
    {
        InitializeComponent();
        button2.Enabled = false;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        proc.StartInfo = new ProcessStartInfo {
            FileName = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "/explorer.exe",
            Arguments = @"D:\",
            UseShellExecute = false
        };
        proc.Start();
        button1.Enabled = false;
        button2.Enabled = true;
    }


    private void button2_Click(object sender, EventArgs e)
    {
        proc.Kill();
        button1.Enabled = true;
        button2.Enabled = false;
    }
Hennie
  • 19
  • 5
user770022
  • 2,899
  • 19
  • 52
  • 79

8 Answers8

37

In your button1_click function you are using '==' for button2.Enabled == true;

This should be button2.Enabled = true;

thattolleyguy
  • 805
  • 6
  • 11
12

button2.Enabled == true ; must be button2.Enabled = true ;.

You have a compare == where you should have an assign =.

Pieter van Ginkel
  • 29,160
  • 8
  • 71
  • 111
5
button2.Enabled == true ;

thats the problem - it should be:

button2.Enabled = true ;
stack72
  • 8,198
  • 1
  • 31
  • 35
5
button2.Enabled == true ;

should be

button2.Enabled = true ;
Gabriel Magana
  • 4,338
  • 24
  • 23
5

Change this

button2.Enabled == true

to

button2.Enabled = true;
Tisho
  • 8,320
  • 6
  • 44
  • 52
123 456 789 0
  • 10,565
  • 4
  • 43
  • 72
3

It is this line button2.Enabled == true, it should be button2.Enabled = true. You are doing comparison when you should be doing assignment.

Alex McBride
  • 6,881
  • 3
  • 29
  • 30
1

Update 2019

This is now IsEnabled

 takePicturebutton.IsEnabled = false; // true
amir
  • 85
  • 8
0

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;
    }
}
Adi Lester
  • 24,731
  • 12
  • 95
  • 110
Nirmal R
  • 1
  • 1