469,964 Members | 1,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

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
Feb 21 '08 #1
5 1256
Shashi Sadasivan
1,435 Expert 1GB
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
Feb 21 '08 #2
kunal pawar
297 100+
I guess ur application is windows based.
U have to capture key event and then fire particular button click event
Feb 21 '08 #3
jamesd0142
469 256MB
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:

Expand|Select|Wrap|Line Numbers
  1. if asc(e.keychar) = "13" then
  2. B1.performclick
  3. end if
  4.  
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.
Feb 21 '08 #4
Thanks all..it worked with both of the solutions.

:)
Feb 21 '08 #5
mafaisal
142 100+
Hello

U Can

Expand|Select|Wrap|Line Numbers
  1. Call Like this
  2. B1_Click(DBNull.Value, EventArgs.Empty)
  3. or
  4. Like Jamesed 
  5.  
  6. B1.PerformClick
  7.  
  8.  
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
Feb 21 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by JCO | last post: by
3 posts views Thread by Dan | last post: by
1 post views Thread by Andrea Williams | last post: by
6 posts views Thread by guoqi zheng | last post: by
2 posts views Thread by Greoasy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.