Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Raising an Event 2

Status
Not open for further replies.

markk609

Programmer
Feb 19, 2005
11
US
What I am trying to do is so simple that I have to think I am missing something quite basic. Nevertheless, here goes.... Suppose that there is a command button control (butn1) on a Windows form which simply opens a message box. What would need to be done to add another command button control (butn2) to the form which, when clicked, would do nothing more than raise the click event for butn1.
 
Easy, goto the sub that handles the btn1.clicked event. go to the far right side of the declaration. At the end you will see: Handles btn1.Clicked. all you have to do is add , btn2.Clicked and it will work.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Could you please tell me the name of the event that gets fired when "enter key" is pressed in textbox?
I have a login screen which has id and password textboxes along with accept button. When enter key is pressed in password box i want to fire accept button click event.
I can do so by adding txtpassword.leave or something to btnaccept.click eventhandler. But i cannot figure out the exact event that gets triggered when enter key is pressed.
I dont want to use leave as leave will get fired even when user back tabs to user id field. I want to capture only when "Enter key " is pressed.
Could you please tell me what is the event name ?
thanks
 
Try setting the form's KeyPreview property to True. Then you can watch for keys like Enter being pressed.

Dale

 
Set the form's AcceptButton property to your accept button, then whenever enter is pressed in a single line textbox your accept button's code will be executed.

Hope this helps.
 
first set the form's keyPreview property to true

then create a keyDown event on the form (or keyUp)

Code:
Private Sub form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

  '' keep watch for certain keys being used
  Select Case e.KeyData
     Case Is = Keys.Enter
       'process

     Case Is = Keys.... 
       'whatever keys you want to watch for

  End Select
End Sub


Dale
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top