如何在c#windows窗体中使用退格键 [英] How to use backspace in c# windows form

查看:188
本文介绍了如何在c#windows窗体中使用退格键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有三个TextBox。



在第三个TextBox输入文本后,想要返回并选择第二个TextBox而不删除第三个TextBox的数据,

使用Backspace键,

实际上,我将光标写入跳转到第三个TextBox第一个字符的第一个位置,然后跳转到第二个TextBox。 />
但总是删除第3个TextBox的最后一个字符。



There have three TextBox.

After typing the text at 3rd TextBox, want to go back and select to 2nd TextBox whithout deleting the 3rd TextBox''s Data,
by using the Backspace key,
Actually, I write the cursor to jump to the first position of first charachter of 3rd TextBox and then jump to 2nd TextBox.
But always deleting the last character of 3rd TextBox.

private void TextBox3_KeyDown(object sender, KeyEventArgs e)
      {
          if (e.KeyValue == 8)
          {
              e.Handled = true;             
              TextBox3.SelectionStart = TextBox3.Text.Length;
              TextBox2.Select();
          }





我该怎么做?



谢谢

ttds



how should i do for that?

thanks
ttds

推荐答案

我同意改变标准行为可能会混淆用户的评论。但是要消耗击键,你应该在KeyDown事件处理程序中设置SuppressKeyPress属性,例如

I agree with the comment that altering a standard behaviour may confuse users. However to consume a keystroke you should set the SuppressKeyPress property in the KeyDown event handler, e.g.
private void TextBox_KeyDown(object sender, KeyEventArgs e) {
  if (e.KeyCode == System.Windows.Forms.Keys.Back) {
    e.SuppressKeyPress = true;
    // no need to set e.Handled
    otherTextBox.Select();
  }
}



这是怎么做的,但我认为你最好不要为TextBoxes设置顺序Tab键顺序使用Tab键和Shift-Tab键在它们之间导航。



Alan


Thats how it''s done, but I do think you would be better off setting a sequential tab order for the TextBoxes and navigating between them using the Tab and Shift-Tab keys.

Alan


如果有三个文本框放在这样的一个标签到另一个的方式,即标签索引是一个接一个,你可以使用 SendKeys.Send [ ^ ]将shift + tab的组合发送到标签到上一个文本框。
If three textboxes are layed out in such a way that one tabs to the other i.e. the tab indexes are one after the other, you can use SendKeys.Send[^] to send a combination of "shift + tab" to tab to previous text box.


这篇关于如何在c#windows窗体中使用退格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆