阻止CTRL + V和Shift +插入文本框c# [英] prevent CTRL+V And Shift+Insert in textbox c#

查看:88
本文介绍了阻止CTRL + V和Shift +插入文本框c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在TextBox keyDown事件中使用代码来阻止CTRL + V和Shift +在文本框中插入



我该怎么办?

i want a code in TextBox keyDown Event to prevent CTRL+V And Shift+Insert in textbox

how i can do it ?

推荐答案

要删除TextBox的上下文菜单,并禁用所有快捷方式:将TextBox的'ShortcutsEnabled属性设置为'false。



或者,您可以通过为TextBox的ContextMenu属性分配空ContextMenu来禁用TextBox的整个上下文菜单:
To get rid of the Context Menu of a TextBox, and disable all short-cuts: set the 'ShortcutsEnabled property of the TextBox to 'false.

Or, you can disable the entire context-menu for a TextBox by assigning an "empty" ContextMenu to the TextBox 'ContextMenu property:
private void YourMainForm_Load(object sender, EventArgs e)
{
    textBox1.ContextMenu = new ContextMenu();
}

如果您需要自定义上下文菜单,当然可以在项目中添加ContextMenu并将其设置为TextBox的ContextMenu。



这是阻止键盘粘贴的一种方法;处理Shift / Insert留给你代码:

If you need a custom Context Menu, you can, of course, add a ContextMenu to your Project and set it to be the ContextMenu of the TextBox.

Here's one way you could block keyboard paste; handling Shift/Insert is left for you to code:

// example of blocking Control-v/V

private bool isControlKeyDown = false;

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (ModifierKeys == Keys.Control) isControlKeyDown = true;

    if (isControlKeyDown && e.KeyCode == Keys.V)
    {
        e.SuppressKeyPress = true;
    }
}

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    isControlKeyDown = ModifierKeys == Keys.Control;
}


你可以做到....



如果e。 keycode = ctrl然后

专注于下一个控制







时按ctrl + v

然后清除文本框



如此移位+插入
you can do that....

if e.keycode=ctrl then
focus on next control

or

when press ctrl+v
then clear text box

as so on shift+insert


i找到解决方案:



只是假文本框的快捷方式启用属性
i find solution:

just false Shortcut Enable property of textbox


这篇关于阻止CTRL + V和Shift +插入文本框c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆