title: How to capture Ctrl-V key event for a Text box
body: <p>I had a textbox that accepts the currency amount only (e.g. 123.40), and I had written the following routine to allow digits, decimal points, and the backspace key only.  The issue is it doesn't allow the user copy and paste values (e.g. Ctrl-V) into the textbox.</p>
  
  <pre><code> Private Sub unitPriceTxtBox_keypress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles unitPriceTxtBox.KeyPress
          If (Not e.KeyChar = ChrW(Keys.Back) And ("0123456789.-").IndexOf(e.KeyChar) = -1) Or (e.KeyChar = "." And unitPriceTxtBox.Text.ToCharArray().Count(Function(c) c = ".") &gt; 0) Then
  
              e.Handled = True
          End If
      End Sub
  </code></pre>
  
  <p>I was doing some research online and the ctrl v key uses the code 22. See <a href="https://social.msdn.microsoft.com/Forums/en-US/5824457e-9112-43ef-83df-7037a36dd365/what-is-the-keychar-for-ctrlc-and-ctrlv-in-c?forum=winforms" rel="nofollow noreferrer">https://social.msdn.microsoft.com/Forums/en-US/5824457e-9112-43ef-83df-7037a36dd365/what-is-the-keychar-for-ctrlc-and-ctrlv-in-c?forum=winforms</a>, but it doesn't seem to work. </p>
  
  <p>Another reference for the keys code is here. 
  <a href="http://Hi,%20%20I%20had%20a%20textbox%20that%20accepts%20the%20currency%20amount%20only%20(e.g.%20123.40),%20and%20I%20had%20written%20the%20following%20routine%20to%20allow%20digit,%20decimal%20points,%20and%20the%20backspace%20key.%20%20The%20issue%20is%20it%20doesn&#39;t%20allow%20the%20user%20copy%20and%20paste%20key%20(e.g.%20Ctrl-V)%20into%20the%20value.%20%20%20%20%20Private%20Sub%20unitPriceTxtBox_keypress(ByVal%20sender%20As%20System.Object,%20ByVal%20e%20As%20KeyPressEventArgs)%20Handles%20unitPriceTxtBox.KeyPress%20%20%20%20%20%20%20%20%20If%20(Not%20e.KeyChar%20=%20ChrW(Keys.Back)%20And%20(%220123456789.-%22).IndexOf(e.KeyChar)%20=%20-1)%20Or%20(e.KeyChar%20=%20%22.%22%20And%20unitPriceTxtBox.Text.ToCharArray().Count(Function(c)%20c%20=%20%22.%22)%20%3E%200)%20Then%20%20%20%20%20%20%20%20%20%20%20%20%20%20e.Handled%20=%20True%20%20%20%20%20%20%20%20%20End%20If%20%20%20%20%20End%20Sub%20%20I%20was%20doing%20some%20research%20online%20and%20the%20ctrl%20v%20key%20uses%20the%20code%2022.%20See%20https://social.msdn.microsoft.com/Forums/en-US/5824457e-9112-43ef-83df-7037a36dd365/what-is-the-keychar-for-ctrlc-and-ctrlv-in-c?forum=winforms,%20but%20it%20doesn&#39;t%20seem%20to%20work.%20%20%20Another%20reference%20for%20the%20keys%20code%20is%20here.%20%20https://msdn.microsoft.com/en-us/library/system.windows.forms.keys(v=vs.110).aspx">https://msdn.microsoft.com/en-us/library/system.windows.forms.keys(v=vs.110).aspx</a></p>
  
  <p>Anyone have any insight?</p>
  
  <p>Thanks.</p>