title: How to disable the accept button in code
body: <p>In Microsoft Visual Basic 2010, a form has a property called AcceptButton. This can be set to the ok button of the form in the designer or by code, like this <code>Me.AcceptButton = Me.OKbutton</code>.</p>
  
  <p>I would like to know how to disable this property in code, with something like <code>Me.AcceptButton = Null</code>, <strong>note</strong> this does not work. In the designer this property can be left set to (none). </p>
  
  <p>The reason I would like to know how to achieve this is as follows. I have a textbox that the user enters data into; when they press enter an error check is done. This uses the following code </p>
  
  <pre><code>    Private Sub textbox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox1.KeyDown
      If e.KeyCode = Keys.Return Then
  </code></pre>
  
  <p>The problem I am having is that this code does not run if the AcceptButton property is enabled, due to the dual use of the return key. I would therefore like to temporarily disable then re-enable the AcceptButton property using code.</p>
  
  <p>If I do not set the AcceptButton this code will run.</p>