我正在尝试制作一个 MaskedTextBox,为了避免用户粘贴值,我正在使用 DataObjectPastingEventHandler
进行处理,但为什么它不起作用?
private void MaskPasteEvent(object sender, DataObjectPastingEventArgs e)
{
e.Handled = true;
}
最佳答案
如果你试试这个会怎么样?
private void MaskPasteEvent(object sender, DataObjectPastingEventArgs e)
{
e.CancelCommand();
}
我基于 MSDN 评论 found here (备注部分的第 4 个要点):
Cancel the paste operation by calling CancelCommand.
在基类 (DataObjectEventArgs) 上调用 CancelCommand 应该在派生的 DataObjectPastingEventsArgs 上将 CommandCancelled 属性设置为 false。
可能有帮助的更多链接:
关于c# - 文本框 DataObjectPastingEventHandler 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20434663/