textbox的Multiline属性为true
在 textbox 中敲入回车跳转到下一个control,在OnKeysPress事件中写入了相应的代码
但是当敲入回车后,它是先在textbox中先回车了一下,再跳转,因此,在textbox.text后面其实多了一个回车,请问该如何将回车消除,或者屏蔽掉这个回车??

解决方案 »

  1.   

    如果希望使用 ENTER 键激活特殊的按钮,可从 TextBox 派生一个类,并在发生 KeyPress 事件时为 ENTER 键提供事件处理代码。
      

  2.   

    在KEYDOWN事件下做----------------------------------------------
    <script>
    function onTest()
    {
    if (event.keyCode == "13")
    {
    alert(document.all["test"].value);
    }
    }
    </script>
    <textarea id="test" onKeydown="onTest();"></textarea>
      

  3.   

    textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 2);
      

  4.   

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

  5.   

    textbox的Multiline属性为true
    改成false.
      

  6.   

    按回車時,你是想執行“OnKeysPress事件中写入了相应的代码”,還是不執行這段代碼
      

  7.   

    textBox1.Text = textBox1.Text.TrimEnd('\n');
      

  8.   

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

  9.   

    在KeyPress事件中:
    if(e.KeyChar==(char)13)e.Handled=true