如题

解决方案 »

  1.   

    textBox1.Text = textBox1.Text.TrimEnd('\r', '\n')
      

  2.   

    原理差不多,你自己改一下吧.文本框按内嵌入脚本函数,使其按下"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"/>&nbsp;
    </form>
      

  3.   

    sdk:ms-help://MS.NETFrameworkSDKv1.1.CHS/cpref/html/frlrfsystemwindowsformsbuttonclassperformclicktopic.htm我以前也做过这个功能,找了很久,后来是一个微软工程师告诉我的,你先捕获到文本框中的按键事件,然后去过滤回车,是回车,就激发提交的click事件,ok
      

  4.   


    方法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()然后手动检查(更烂了)
      

  5.   

    to chili:
      帮你顶:D
      

  6.   

    我是在TextBox中,当回车时候 跳转到下个控件,但是当每次跳转后TextBox依然有回车符,
    请问lovewindy(LOVE风云),该如何过滤掉这个回车符,谢谢
      

  7.   

    很简单的问题
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if(e.KeyChar == (char)Keys.Enter)
    {
    e.Handled = true;
    }
    }
      

  8.   

    keypress 事件,trim掉最后的\r\n
      

  9.   

    MyLf(不睡觉的鱼) 
    =======================
    这个不合适,因为我是在一个Baseform中对这个Form的所有Control加的事件处理
     xamaizi(ecogiser)
    ==========================
    那我要是在字符串中间回车呢?
      

  10.   

    我晕了
    我回的帖子你都不看啊????!!!
    最直接的方法当然是override WndProc(),极其鄙视楼主
      

  11.   

    lovewindy(LOVE风云)
    ===========================
    你说的怎么过滤enter??
      

  12.   

    ybzsu() 你的方法1怎么用啊,,,看不懂!!!
      

  13.   


    新建一个类会吧?
    让这个类继承TextBox会吧?
    class myTextBox:System.Windows.Forms.TextBox
    然后在新建的类中override WndProc(),如果不会就打override然后空格,拉到最下面,点那个WndProc...然后在函数体中处理消息
    if(m.LParam==**&&m.WParam)
    {
    //你要的处理
    return;
    }
    base.WndProc (ref m);
      

  14.   


    新建一个类会吧?
    让这个类继承TextBox会吧?
    class myTextBox:System.Windows.Forms.TextBox
    然后在新建的类中override WndProc(),如果不会就打override然后空格,拉到最下面,点那个WndProc...然后在函数体中处理消息
    if(m.LParam==**&&m.WParam=*******)
    {
    //你要的处理
    return;
    }
    base.WndProc (ref m);
      

  15.   

    ding!
    该怎样消除回车字符,,,我是在一个Baseform中对这个Form的所有Control加的事件处理
      

  16.   

    那就对这个form的WndProc进行ovdrride
      

  17.   

    [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.
      

  18.   

    这有点太大材小用了吧
    而且如果程序没关之前Enter键就挂啦!
      

  19.   

    ybzsu() 
    我不太明白你说的方法怎么设置enter无效~~~