Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-designate-a-windows-forms-button-as-the-accept-button.md
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.1 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
Designate a Button as the Accept Button 03/30/2017
csharp
vb
cpp
buttons [Windows Forms], default on Windows Forms
Accept button on Windows Forms
Button control [Windows Forms], designating as default
Windows Forms controls, default button on form
22cc9da6-b913-4e04-9554-dee443ac5c3a

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

On any Windows Form, you can designate a xref:System.Windows.Forms.Button control to be the accept button, also known as the default button. Whenever the user presses the ENTER key, the default button is clicked regardless of which other control on the form has the focus.

Note

The exceptions to this are when the control with focus is another button — in that case, the button with the focus will be clicked — or a multiline text box, or a custom control that traps the ENTER key.

To designate the accept button

  1. Set the form's xref:System.Windows.Forms.Form.AcceptButton%2A property to the appropriate xref:System.Windows.Forms.Button control.

    Private Sub SetDefault(ByVal myDefaultBtn As Button)  
      Me.AcceptButton = myDefaultBtn
    End Sub  
    
    private void SetDefault(Button myDefaultBtn)  
    {  
       this.AcceptButton = myDefaultBtn;  
    }  
    
    private:  
       void SetDefault(Button ^ myDefaultBtn)  
       {  
          this->AcceptButton = myDefaultBtn;  
       }  
    

See also