Capture CTRL+V or paste in a textbox in .NET

前端 未结 1 558
执笔经年
执笔经年 2021-01-14 02:37

VB.NET 2010 - I have a RichTextbox in which the user can manually enter data or copy/paste from another source. After the data is complete he hits go and a few key words are

1条回答
  •  离开以前
    2021-01-14 03:04

    In most cases, examining the KeyDown event should be good enough along with using a temporary RichTextBox to modify the incoming text:

    Private Sub RichTextBox1_KeyDown(sender As Object, e As KeyEventArgs) _
                                     Handles RichTextBox1.KeyDown
      If e.Modifiers = Keys.Control AndAlso e.KeyCode = Keys.V Then
    
        Using box As New RichTextBox
          box.SelectAll()
          box.SelectedRtf = Clipboard.GetText(TextDataFormat.Rtf)
          box.SelectAll()
          box.SelectionBackColor = Color.White
          box.SelectionColor = Color.Black
          RichTextBox1.SelectedRtf = box.SelectedRtf
       End Using
    
       e.Handled = True
      End If
    End Sub
    

    Note: Missing any error checking.

    0 讨论(0)
提交回复
热议问题