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,687
  • 17
  • 48
  • 76

8 Answers8

33

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

This should be button2.Enabled = true;

thattolleyguy
  • 765
  • 5
  • 11
12

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

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

Pieter van Ginkel
  • 28,744
  • 8
  • 70
  • 108
5
button2.Enabled == true ;

thats the problem - it should be:

button2.Enabled = true ;
stack72
  • 8,050
  • 1
  • 30
  • 35
5

Change this

button2.Enabled == true

to

button2.Enabled = true;
Tisho
  • 7,870
  • 6
  • 42
  • 52
123 456 789 0
  • 10,482
  • 4
  • 41
  • 69
4
button2.Enabled == true ;

should be

button2.Enabled = true ;
Gabriel Magana
  • 4,209
  • 23
  • 22
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,771
  • 3
  • 30
  • 30
1

Update 2019

This is now IsEnabled

 takePicturebutton.IsEnabled = false; // true
Java.Her
  • 77
  • 6
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,307
  • 12
  • 89
  • 107
Nirmal R
  • 1
  • 1