Press Enter and Executre button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hmkaddoura
    New Member
    • Feb 2008
    • 18

    Press Enter and Executre button

    Hi All,
    in my form I have two textboxes (T1,T2) and two buttons (B1,B2)

    how can i insert text in T1 and press enter to execute B1 event, and insert text in T2 and press enter to execute B2 event.

    the only thing that i found is that I set in the Form itself the property of AcceptButton and choose which button (only one button)

    is there away for doing so? (i know it is possible but need help :) )

    Regards,
    HK
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    I think you would have to use the keydown event of the form and in that even check which textbox is set to focus, and raise the appropriate event accordingly

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      I guess ur application is windows based.
      U have to capture key event and then fire particular button click event

      Comment

      • jamesd0142
        Contributor
        • Sep 2007
        • 471

        #4
        Originally posted by hmkaddoura
        Hi All,
        in my form I have two textboxes (T1,T2) and two buttons (B1,B2)

        how can i insert text in T1 and press enter to execute B1 event, and insert text in T2 and press enter to execute B2 event.

        the only thing that i found is that I set in the Form itself the property of AcceptButton and choose which button (only one button)

        is there away for doing so? (i know it is possible but need help :) )

        Regards,
        HK
        Double click T1 (textbox) and open the keypress event then use code such as:

        [code=text]
        if asc(e.keychar) = "13" then
        B1.performclick
        end if
        [/code]

        You see the asci code for enter key is "13"
        Everytime a key is pressed when the textbox is in focus it will check to see if it was the enter key.

        Comment

        • hmkaddoura
          New Member
          • Feb 2008
          • 18

          #5
          Thanks all..it worked with both of the solutions.

          :)

          Comment

          • mafaisal
            New Member
            • Sep 2007
            • 142

            #6
            Hello

            U Can

            Code:
            Call Like this
            B1_Click(DBNull.Value, EventArgs.Empty)
            or
            Like Jamesed 
            
            B1.PerformClick
            Originally posted by hmkaddoura
            Hi All,
            in my form I have two textboxes (T1,T2) and two buttons (B1,B2)

            how can i insert text in T1 and press enter to execute B1 event, and insert text in T2 and press enter to execute B2 event.

            the only thing that i found is that I set in the Form itself the property of AcceptButton and choose which button (only one button)

            is there away for doing so? (i know it is possible but need help :) )

            Regards,
            HK

            Comment

            Working...