Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

How to: Designate a Windows Forms Button as the Cancel Button 

On any Windows Form, you can designate a Button control to be the cancel button. A cancel button is clicked whenever the user presses the ESC key, regardless of which other control on the form has the focus. Such a button is usually programmed to enable the user to quickly exit an operation without committing to any action.

To designate the cancel button

  • Set the form's CancelButton property to the appropriate Button control.

    Private Sub SetCancelButton(ByVal myCancelBtn As Button)
       Me.CancelButton = myCancelBtn
    End Sub
    
    
private void SetCancelButton(Button myCancelBtn)
{
   this.CancelButton = myCancelBtn;
}

private void SetCancelButton(Button myCancelBtn) 
{
   this.set_CancelButton(myCancelBtn);
}

private:
   void SetCancelButton(Button ^ myCancelBtn)
   {
      this->CancelButton = myCancelBtn;
   }

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.