在C#文本框中禁用粘贴/Ctrl + v(基于窗口的应用程序) [英] Disable Paste/Ctrl+v in C# textbox (Window based application)

查看:132
本文介绍了在C#文本框中禁用粘贴/Ctrl + v(基于窗口的应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在C#文本框中禁用了粘贴/Ctrl + v.

Hi,

I hv to disable the Paste/Ctrl+v in C# textbox. Please help me?

推荐答案

此代码将通过键禁用剪切/复制和粘贴选项(Ctrl + X,Ctrl + C和Ctrl + V). >
This code will disable cut/copy and paste options( Ctrl+X,Ctrl+C and Ctrl+V) through keys.
private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control == true)
            {
                MessageBox.Show("Cut/Copy and Paste Options are disabled");
            }
        }


您好,请尝试以下代码,

Hi dear try this code,

private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
       {
           if (e.KeyChar == 22)
               e.Handled = true;
         
        }


禁用右键单击文本框:

在表单上放置一个空白的contextmenuestrip,并将其重命名为ex:mycontext,然后在mycontext中设置文本框的Contextmenuestrip属性.用户将无法右键单击您的文本框.

要禁用复制和粘贴,请将此代码放在文本框的KeyDown事件处理程序上


For disabling right click on your textbox:

Put a blank contextmenuestrip on your form and rename it for ex: mycontext, then set the Contextmenuestrip property of your text box in mycontext. User will not be able right click on your textbox.

For disabling copy and paste put this code on KeyDown Event handler of your textbox


private void textBox1_KeyDown(object sender, KeyEventArgs e)
  {
   if (e.Modifiers == Keys.Control)
   {
     e.Handled = true;
    textBox1.SelectionLength = 0;
   }
  }


这篇关于在C#文本框中禁用粘贴/Ctrl + v(基于窗口的应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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