比如一个密码输入框,是不允许输入全角字符的,但是我可以粘帖进去,有没有什么办法不让粘帖呢?
谢谢大家!

解决方案 »

  1.   


    TextBox1.ShortcutsEnabled=false;//禁用快捷键
    TextBox1.AllowDrop=false;//不接受拖放到密码框里的数据
      

  2.   

    进入到TextBox的时候吧CilipBoard清空
      

  3.   


            public static bool IsDBCString(string input)
            {
                char[] c = input.ToCharArray();
                for (int i = 0; i < c.Length; i++)
                {
                    if (c[i] == 12288)
                    {
                        return true;
                    }
                    if (c[i] > 65280 && c[i] < 65375)
                        return true;
                }
                return false;
            }
      

  4.   

    选textbox的keypress事件.private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                
                if (e.KeyChar == 65) 
                {
                    e.KeyChar = (char)0 ;
                }
            }
    上面的代码意思是 如果你按下键发送的ascii码是65,也就是大写的A,那么你发送的ascii为0,也就是什么也没有(严格不能这样说,为了理解)你找到全角字符的ascii码段, 然后用if(e.keychar<全角字符asicc起始码 || e.keychar>全角字符asicc起末码){干你想干的事}至于ascii码.你可以去查ascii表.也可以自己写一个小程序来查看
      

  5.   

    TextBox1.ShortcutsEnabled=false;//禁用快捷键 
    我在vs2003中 找不到阿
      

  6.   

    屏蔽ctrl+v 和右键
    http://www.csdn.net/expert/topic/720/720999.xml?temp=.1258814 
    http://www.vckbase.com/document/viewdoc.asp?id=424 
      

  7.   

    下面是无粘贴TextBox源码 using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Drawing; 
    using System.Data; 
    using System.Linq; 
    using System.Text; 
    using System.Windows.Forms; namespace MyTest 

    public partial class UnPasteTextBox : TextBox 

    public UnPasteTextBox() 

    InitializeComponent(); 
    } //粘贴消息 
    public const int WM_PASTE = 0x0302; protected override void WndProc(ref Message m) 

    if (m.Msg != WM_PASTE) base.WndProc(ref m); 


    }
      

  8.   

    Main 之前加上 [MTAThread]
      

  9.   

    Clipboard.GetData(DataFormats.StringFormat);
      

  10.   

    也可以
            private void textBox1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Control && e.KeyValue == (int)Keys.V)
                    e.SuppressKeyPress = true;
            }还可以尝试拦截WM_PASTE消息
      

  11.   

     public static bool IsDBCString(string input)
            {
                char[] c = input.ToCharArray();
                for (int i = 0; i < c.Length; i++)
                {
                    if (c[i] == 12288)
                    {
                        return true;
                    }
                    if (c[i] > 65280 && c[i] < 65375)
                        return true;
                }
                return false;
            }
    请问下这个方法里边的数字是什么意思?
      

  12.   

    或者
    public Form1()
            {
                InitializeComponent();            this.KeyPreview = true;
            }        private void Form1_KeyDown(object sender, KeyEventArgs e)
            {
                if (ActiveControl != null && ActiveControl.Name == textBox1.Name)
                    if (e.Control && e.KeyValue == (int)Keys.V)
                        e.SuppressKeyPress = true;
            }
      

  13.   

     public bool isCharDBC(string input)
            {
              bool Flag=false;
                char[] c = input.ToCharArray();
                for (int i = 0; i < c.Length; i++)
                {            if (c > 65280 && c < 65375)
                   { Flag=true;
                  break;
                  }
               }
    return Flag;
            }