I have this code:
private void btnAddDataToCSV_Click(object sender, EventArgs e)
{
var myProcess = new Process();
this.Enabled = false;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(Excel_Exit);
myProcess.StartInfo.FileName = "D:\\MyCsvFile.csv";
myProcess.Start();
}
public void Excel_Exit(object sender, System.EventArgs e)
{
MessageBox.Show("Success!!");
this.Enabled = true;
}
The code works as far as graying out all the buttons on my C# user form and opening the csv file in Excel. When I close Excel the exit event fires displaying a message "Success!!" But it doesn't re-enable the buttons after closing Excel.
I am getting the error
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
on the this.Enabled = true;
line.
As you can see from my comments below. I have now come to to realization that I cannot figure out how to disable even a single button.
private void btnAddDataToCSV_Click(object sender, EventArgs e)
{
var myProcess = new Process();
button1.Enabled = false;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(Excel_Exit);
myProcess.StartInfo.FileName = "D:\\MyCsvFile.csv";
myProcess.Start();
}
public void Excel_Exit(object sender, System.EventArgs e)
{
button1.Enabled = true;
}
The event is firing because the code below works... (displays success!!)
private void btnAddDataToCSV_Click(object sender, EventArgs e)
{
var myProcess = new Process();
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(Excel_Exit);
myProcess.StartInfo.FileName = "D:\\MyCsvFile.csv";
myProcess.Start();
}
public void Excel_Exit(object sender, System.EventArgs e)
{
MessageBox.Show("Success!!");
}
Any help would be greatly appreciated.