I decided to create a login form and use the Form.AcceptButton
property for the first time. I have a problem with locking controls while my Login
function is running.
When I hit enter to login, the form freezes before the cursor changed to the
WaitCursor
and the controls are locked.When I click the login button, the form freezes after the cursor changes to the
WaitCursor
and the controls are locked (preferred behavior).
Here is my code (simplified):
private void btnLogin_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
// foreach loop that sets Enabled = false on all controls on form
LockControls();
// this function tries to login to SOAP web service, sometimes it takes few seconds
Login();
this.Cursor = Cursors.Default;
// foreach loop that sets Enabled = true on all controls on form
UnlockControls();
}