locked
VB.Net Windows Application Text Box/ button Control Question RRS feed

  • 問題

  • Hi

    你好! 我想問有無方法可以做到當個user 係個text box 度 press enter
    佢會trigger 某個button 呢?
    e.g.  我有幾個唔同既text box
    當佢係果d textbox 度打完字後 press enter 佢就會做某d o野
    depend on the textbox they are on?

    唔知可以點先做到呢

    謝謝大家

    Chi
    2008年5月2日 下午 03:42

解答

所有回覆

  • Hi Chi,

     

    You may catpure the Enter event of the TextBox control, FYI: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.enter(VS.71).aspx

     

    Regards,

    Colt

    2008年5月4日 上午 05:42
  • Hi Colt

    Thanks for your information. Do you mean on the Enter Event. I need to do a If statement to check if the key they press is equal to "keys.Enter"

    Many thanks

    Chi
    2008年5月6日 上午 07:32
  • Well, You may write code in KeyDown or KeyUp event.

     

    MSDN Library -- Control.KeyDown Event

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown(VS.71).aspx

     

     

    About checking if it is "enter" key, you could check with the

    Code Snippet
    If (e.KeyChar == 13)

     

     


    2008年5月7日 上午 02:05
  • Hi Chi,

     

    The Enter event will be fired without any if-else checking, when you press Enter on the control.

     

    Or you can capture the key change / up event, and then determine what is the input char (keyChar).

     

    Regards,

    Colt

    2008年5月9日 上午 01:37
  • Just want to clarify that the Enter event, is about the focusing of the control. I.e., it is fired when you "select" the control, by "tab", mouse click, etc. It may not have any relation with pressing Enter key.

     

    Keys related events are:

       1. KeyDown
       2. KeyPress
       3. KeyUp

    2008年5月9日 上午 06:25