java 监控ctrl v_捕获CTRL V或粘贴到.NET中的文本框中

VB.NET 2010 - 我有一个RichTextbox,用户可以在其中手动输入数据或从其他来源复制/粘贴 . 数据完成后,他会点击并突出显示几个关键字 . 我的问题是,如果他从其他来源复制/粘贴格式也会被复制 . 好吧,有时外部来源有白色字体,我的文本框有白色背景,所以看起来他没有粘贴,他一次又一次地做 .

我正在寻找的是一种拦截粘贴操作到文本框的方法,这样我就可以将该文本粘贴为纯ASCII而无需格式化 .

在使用KeyDown进行实验后进行编辑

Private Sub txtRch_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtRch.KeyDown

If e.Modifiers = Keys.Control AndAlso e.KeyCode = Keys.V Then

With txtRch

Dim i As Integer = .SelectionStart 'cache the current position

.Select(0, i) 'select text from start to current position

Dim s As String = .SelectedText 'copy that text to a variable

.Select(i, .TextLength) 'now select text from current position to end

Dim t As String = .SelectedText 'copy that text to a variable

Dim u As String = s & Clipboard.GetText(TextDataFormat.UnicodeText) & t 'now concatenate the first chunk, the new text, and the last chunk

.Clear() 'clear the textbox

.Text = u 'paste the new text back into textbox

.SelectionStart = i 'put cursor back to cached position

End With

'the event has been handled manually

e.Handled = True

End If

End Sub

这似乎工作,我的所有文本都被保留,其所有ASCII . 我想如果我想更进一步,我也可以采用我的RichTextbox的字体和前景,选择所有文本,然后将字体和前景分配给选择 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值