下面是无粘贴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); } } }
TextBox1.ShortcutsEnabled=false;//禁用快捷键
TextBox1.AllowDrop=false;//不接受拖放到密码框里的数据
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;
}
{
if (e.KeyChar == 65)
{
e.KeyChar = (char)0 ;
}
}
上面的代码意思是 如果你按下键发送的ascii码是65,也就是大写的A,那么你发送的ascii为0,也就是什么也没有(严格不能这样说,为了理解)你找到全角字符的ascii码段, 然后用if(e.keychar<全角字符asicc起始码 || e.keychar>全角字符asicc起末码){干你想干的事}至于ascii码.你可以去查ascii表.也可以自己写一个小程序来查看
我在vs2003中 找不到阿
http://www.csdn.net/expert/topic/720/720999.xml?temp=.1258814
http://www.vckbase.com/document/viewdoc.asp?id=424
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);
}
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyValue == (int)Keys.V)
e.SuppressKeyPress = true;
}还可以尝试拦截WM_PASTE消息
{
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;
}
请问下这个方法里边的数字是什么意思?
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;
}
{
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;
}