【问题标题】:make program press the enter key on textbox focus使程序在文本框焦点上按回车键
【发布时间】:2014-08-30 12:53:54
【问题描述】:

如果这不可能,请原谅我,这是场景。

我有 2 个文本框,我在 textbox1 上输入一些内容并按回车,文本转到 textbox2 并且程序在 textbox2 上按回车键(用户不会按回车键)。

这是我在 textbox1_keydown 中的内容

if e.keycode = keys.enter then
  str = textbox1.text
  textbox2.focus()
  textbox2.text = str
  'Make textbox2 press the enter key here, without user pressing it on keyboard
end if

【问题讨论】:

  • 第二次回车是转到textbox2的下一行吗?
  • 这是一个 Windows 窗体程序吗?
  • 不要编辑问题以包含您的解决方案...为您的问题创建一个答案(是的,您可以回答自己的问题)。

标签: vb.net winforms


【解决方案1】:

找到答案

if e.keycode = keys.enter then
  str = textbox1.text
  textbox2.focus()
  textbox2.text = str
  'Make textbox2 press the enter key here, without user pressing it on keyboard
  SendKeys.Send("{ENTER}")
end if

【讨论】:

    【解决方案2】:
      If e.keycode = Keys.Enter Then
              '/* Check whether textbox1 is empty or not */
           If textbox1.text <> "" Then
              textbox2.text = ""
              textbox2.text = textbox1.text
              SendKeys.Send("{ENTER}")
           Else
             '/* if textbox1 is empty then cursor focus on textbox1 only */
              textbox1.focus()
           End If
       End If
    

        If e.keycode = Keys.Enter Then
             textbox2.text = ""
             textbox2.text = textbox1.text
             SendKeys.Send("{ENTER}")
        End If
    

    【讨论】:

      猜你喜欢
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多