make程序按文本框焦点上的回车键

时间:2014-08-30 01:44:31

标签: vb.net winforms

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

我有两个文本框,我在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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

  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

OR

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