PDA

View Full Version : Button - detect function that is running and is done running?



Aquttian
07-22-2015,
You know in the *.Designer.cs file, you see a button with the event handler. In this case, "myButton.click += new System.EventHandler(this.myButton_Click);" run the event handler when a button is clicked.

I wonder how do I detect if this function "myButton_Click" is running so I can do the cursor to a WaitCursor and once the script is finish running with a return event would I change the cursor to a Default.

There got to be an easier way but I can't pin-point it. I do know I need to do a callback or delegate inside that "myButton_Click" function. So, can anyone provide a sample script that can detect when the function is running and is done.

THanks...

arissfdron
07-22-2015,
Can't do it unless you can change the function.

Armandoben
07-24-2015,
In the method that handles the event, myButton_Click, why not wrap the code in a try/finally block? Save the cursor on entry, change it to a WaitCursor, then in the finally block revert to the initial saved cursor?

ArmandoRorb
07-24-2015,
I did a little of that today and I realized that if I used this "return;" part of the script (see sample code below) then it wouldn't work becuase it exit the function.

ArthurDen
07-27-2015,
You can do it, but it would require you to wire up eventhandlers manually in the Form's constructor rather than letting the Designer generate that code.

[code=C#]class Form1 : Form
{
public Form1()
{
InitializeComponent();

//the Click events should still be null at this point.

//this is what you'd have to do for each Click event
//to call StartBusy(), then the appropriate eventhandler,
//then call EndBusy():