Cancel Button 'Esc" not working

kpgraci

Active member
Joined
Feb 21, 2011
Messages
30
Location
New Orleans
Programming Experience
10+
I have a login form (startup form) with OK/Cancel button, and each set on the form as Accept/Cancel button - works fine.

After login my main form loads, it has keypreview on. This main form opens a new form (after user clicks a client search button) with an OK/Cancel set up the same as the login form.

On this search form, the Enter key works (it calls the OKbutton click just fine), but the Esc key does not.

The cancelbutton property if set to the cancel button, and this form does not use keypreview.

The form has focus, I clicked it to be sure, but in any case the enter key works.

What could be wrong?
 
Resolved (in record time)

Apparently, you should not name a button 'CancelButton', becuase that conflicts with the form's me.CancelButton property and it must get confused.

I renamed my button to Buttoncancel and now it works.

I did not receive a compile error or a warning, I figured it out when I tried to manually set the me.CancelButton in form load. I was setting the property
in the designer.

go figure.
 
When I name a button "CancelButton" I get this warning:
WithEvents variable 'CancelButton' conflicts with property 'CancelButton' in the base class 'Form' and should be declared 'Shadows'.
At least it is an indication of a conflict in regard to the CancelButton functionality, even though the proposed resolution is not a good one in this case, giving it a non-conflicting name like you did is better.
 
Back
Top