C# .NET Winforms Form CancelButton not working

I've recently had a problem that the "CancelButton" property on a WinForm wasn't working. When it should cause the form to close when you press the Escape (ESC) key, nothing was actually happening.

I put this down to the fact that I'd been on a very long bike ride the day before and was rather tired but it's because I'd named the button "CancelButton" which is of course the same as the property on the form causing a circular reference.

I thought I'd post this rather simple fix because it's so stupidly simple someone may overlook the solution on a day they're tired too.

Comments

Popular posts from this blog

Windows Server 2016, 2019, 2022, Windows 10 and Windows 11: Date and time "Some settings are managed by your organization".

TFTPD32 or TFTPD64 reports Bind error 10013 An attempt was made to access a socket in a way forbidden by its access permissions.

Windows Server 2019 desktop icons such as My Computer, Windows cannot access the specified device, path, or file.