如何实现象MSN那样敲enter发送,而在文本中并没有回车符 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 textBox1.Text = textBox1.Text.TrimEnd('\r', '\n') 原理差不多,你自己改一下吧.文本框按内嵌入脚本函数,使其按下"Ctrl+回车键"后,调用Form1表单的"btnSend"按钮进行快速提交.脚本函数:<script language="javascript">function SendMsg(){ if(event.keyCode==10) document.Form1.btnSend.click();}</script>最后记得把Web表单和提交按钮的命名和脚本相对应.<form id="Form1" runat="server"><asp:TextBox id="Content" TextMode="MultiLine" Width="100%" Height="100px" OnKeyPress="SendMsg()" runat="server"/><asp:button id="btnSend" Text="发送" OnClick="Send_Click" runat="server"/> </form> sdk:ms-help://MS.NETFrameworkSDKv1.1.CHS/cpref/html/frlrfsystemwindowsformsbuttonclassperformclicktopic.htm我以前也做过这个功能,找了很久,后来是一个微软工程师告诉我的,你先捕获到文本框中的按键事件,然后去过滤回车,是回车,就激发提交的click事件,ok 方法1。public class tb : System.Windows.Forms.TextBox然后protected override void WndProc(ref Message m)方法2.private void textBox4_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e){if(e.KeyChar==(char)Keys.Enter){.........}}这种方法textbox.Text后面还是会多个回车,还要你自己处理当然还可以textnox_TextChanged()然后手动检查(更烂了) to chili: 帮你顶:D 我是在TextBox中,当回车时候 跳转到下个控件,但是当每次跳转后TextBox依然有回车符,请问lovewindy(LOVE风云),该如何过滤掉这个回车符,谢谢 很简单的问题private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e){ if(e.KeyChar == (char)Keys.Enter) { e.Handled = true; }} keypress 事件,trim掉最后的\r\n MyLf(不睡觉的鱼) =======================这个不合适,因为我是在一个Baseform中对这个Form的所有Control加的事件处理 xamaizi(ecogiser)==========================那我要是在字符串中间回车呢? 我晕了我回的帖子你都不看啊????!!!最直接的方法当然是override WndProc(),极其鄙视楼主 lovewindy(LOVE风云)===========================你说的怎么过滤enter?? ybzsu() 你的方法1怎么用啊,,,看不懂!!! 。新建一个类会吧?让这个类继承TextBox会吧?class myTextBox:System.Windows.Forms.TextBox然后在新建的类中override WndProc(),如果不会就打override然后空格,拉到最下面,点那个WndProc...然后在函数体中处理消息if(m.LParam==**&&m.WParam){//你要的处理return;}base.WndProc (ref m); 。新建一个类会吧?让这个类继承TextBox会吧?class myTextBox:System.Windows.Forms.TextBox然后在新建的类中override WndProc(),如果不会就打override然后空格,拉到最下面,点那个WndProc...然后在函数体中处理消息if(m.LParam==**&&m.WParam=*******){//你要的处理return;}base.WndProc (ref m); ding!该怎样消除回车字符,,,我是在一个Baseform中对这个Form的所有Control加的事件处理 那就对这个form的WndProc进行ovdrride [DllImport("user32.dll")]static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);[DllImport("user32.dll")]static extern bool UnregisterHotKey(IntPtr hWnd, int id);private const int VK_RETURN = 0xD;private void Form1_Load(object sender, System.EventArgs e){ RegisterHotKey(textBox1.Handle, 1, 0, VK_RETURN);}private void Form1_Closed(object sender, System.EventArgs e){ UnregisterHotKey(textBox1.Handle, 1);}private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e){ if(e.KeyCode == Keys.Enter) { if(richTextBox1.Text.Length != 0) { richTextBox1.Text += "\r\n"; } richTextBox1.Text += textBox1.Text; } }that's ok. 这有点太大材小用了吧而且如果程序没关之前Enter键就挂啦! ybzsu() 我不太明白你说的方法怎么设置enter无效~~~ C#中equal与==区别 datagridview 排序 "***”列不属于表“****” textbox的值写入数据库碰到的问题 关于处于图形的颜色问题! 文件下载 返回表中选重的是第几行 怎么在一棵树里再插入一棵树 System.InvalidOperationException: ExecuteReader: CommandText 属性尚未初始化 ASP.net 网页客户端不能看到图像 客户端激活对象的释放 怎么判断两个网址是一个网站。!!!
调用Form1表单的"btnSend"按钮进行快速提交.脚本函数:
<script language="javascript">
function SendMsg(){
if(event.keyCode==10)
document.Form1.btnSend.click();
}
</script>最后记得把Web表单和提交按钮的命名和脚本相对应.
<form id="Form1" runat="server">
<asp:TextBox id="Content" TextMode="MultiLine" Width="100%" Height="100px"
OnKeyPress="SendMsg()" runat="server"/>
<asp:button id="btnSend" Text="发送" OnClick="Send_Click" runat="server"/>
</form>
方法1。public class tb : System.Windows.Forms.TextBox然后
protected override void WndProc(ref Message m)
方法2.private void textBox4_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)Keys.Enter)
{
.........
}
}
这种方法textbox.Text后面还是会多个回车,还要你自己处理
当然还可以textnox_TextChanged()然后手动检查(更烂了)
帮你顶:D
请问lovewindy(LOVE风云),该如何过滤掉这个回车符,谢谢
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
}
}
=======================
这个不合适,因为我是在一个Baseform中对这个Form的所有Control加的事件处理
xamaizi(ecogiser)
==========================
那我要是在字符串中间回车呢?
我回的帖子你都不看啊????!!!
最直接的方法当然是override WndProc(),极其鄙视楼主
===========================
你说的怎么过滤enter??
新建一个类会吧?
让这个类继承TextBox会吧?
class myTextBox:System.Windows.Forms.TextBox
然后在新建的类中override WndProc(),如果不会就打override然后空格,拉到最下面,点那个WndProc...然后在函数体中处理消息
if(m.LParam==**&&m.WParam)
{
//你要的处理
return;
}
base.WndProc (ref m);
新建一个类会吧?
让这个类继承TextBox会吧?
class myTextBox:System.Windows.Forms.TextBox
然后在新建的类中override WndProc(),如果不会就打override然后空格,拉到最下面,点那个WndProc...然后在函数体中处理消息
if(m.LParam==**&&m.WParam=*******)
{
//你要的处理
return;
}
base.WndProc (ref m);
该怎样消除回车字符,,,我是在一个Baseform中对这个Form的所有Control加的事件处理
static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers,
uint vk);[DllImport("user32.dll")]
static extern bool UnregisterHotKey(IntPtr hWnd, int id);private const int VK_RETURN = 0xD;private void Form1_Load(object sender, System.EventArgs e)
{
RegisterHotKey(textBox1.Handle, 1, 0, VK_RETURN);
}private void Form1_Closed(object sender, System.EventArgs e)
{
UnregisterHotKey(textBox1.Handle, 1);
}private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
if(richTextBox1.Text.Length != 0)
{
richTextBox1.Text += "\r\n";
}
richTextBox1.Text += textBox1.Text;
}
}that's ok.
而且如果程序没关之前Enter键就挂啦!
我不太明白你说的方法怎么设置enter无效~~~