Phreak Posted March 24, 2003 Posted March 24, 2003 Ok, I know how to set the tab index of my controls, but that is still a little slow and inconvenient. How could I setup a text box and button so that when I was done entering in data into the text field, it would submit the data using the button, by just pushing the ENTER key? Quote If it works... don't worry, I'll fix it.
*Experts* Nerseus Posted March 24, 2003 *Experts* Posted March 24, 2003 Set the Form's AcceptButton property to the button you want to click when "Enter" is pressed. A form also has a CancelButton property that is auto-magically clicked when they press Escape. :) Certain controls, such as a multi-line textbox, will NOT click the button even if it's the AcceptButton for the form. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
hitechoutlaw Posted March 24, 2003 Posted March 24, 2003 i was gona ask that same question later. i'm remaking my chat program in vb.net from vb6 and i have a RichTextBox for where you type your message to send. is there a way to where when you press "shift"+"enter" it enters down instead of pressing the button you told it to when you press enter? thx Quote
Phreak Posted March 25, 2003 Author Posted March 25, 2003 ... is there a way to where when you press "shift"+"enter" it enters down instead of pressing the button you told it to when you press enter? thx I second that... Quote If it works... don't worry, I'll fix it.
*Gurus* divil Posted March 25, 2003 *Gurus* Posted March 25, 2003 You could inherit from TextBox and override the ProcessDialogKey method like this: Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean If (keyData And Keys.Return) = Keys.Return Then If (keyData And Keys.Shift) = 0 Then If TypeOf TopLevelControl Is Form Then If Not DirectCast(TopLevelControl, Form).AcceptButton Is Nothing Then DirectCast(TopLevelControl, Form).AcceptButton.PerformClick() End If End If Return True Else Return False End If Else Return MyBase.ProcessDialogKey(keyData) End If End Function Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
hitechoutlaw Posted March 25, 2003 Posted March 25, 2003 i have a problem with that code. when i put in that code it takes these keys like i'm pressing enter: ] o / m - and these on the number pad: - / it works perfect when i don't have this code in, any suggestions? thx Quote
*Gurus* divil Posted March 25, 2003 *Gurus* Posted March 25, 2003 That's weird... I haven't time to look in to it now but if anyone else finds out why this is happening I'd be interested! Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Phreak Posted March 25, 2003 Author Posted March 25, 2003 I have the EXACT same problem with the EXACT same keys. I will keep looking into it. Let me know if anyone finds anything out, I will do the same. Quote If it works... don't worry, I'll fix it.
Phreak Posted March 25, 2003 Author Posted March 25, 2003 I've come up with a solution to the problem (there may be an easier way, but this works... kind of), however, I can't get it to work for the / key. (otherwise known as the ? key). I got the / on the numpad to work, but not the other one. Here is the code: Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean If (keyData And Keys.Return) = Keys.Return Then If (keyData And Keys.Shift) = 0 Then If WrongKey(keyData) = False Then If TypeOf TopLevelControl Is Form Then If Not DirectCast(TopLevelControl, Form).AcceptButton Is Nothing Then DirectCast(TopLevelControl, Form).AcceptButton.PerformClick() End If End If Return True End If Return False Else Return False End If Else Return MyBase.ProcessDialogKey(keyData) End If End Function Private Function WrongKey(ByVal PKEY As System.Windows.Forms.Keys) As Boolean If PKEY <> Nothing Then Select Case PKEY Case Keys.OemMinus Return True Case Keys.Subtract Return True Case Keys.O Return True Case Keys.OemCloseBrackets Return True Case Keys.M Return True Case Keys.Divide Return True Case Keys.Separator Return True Case Else Return False End Select Else Return False End If End Function Let me know if anyone knows the key value or "other name" for the forward slash (/) key to implement into the function. Quote If it works... don't worry, I'll fix it.
Phreak Posted March 25, 2003 Author Posted March 25, 2003 Got it! Substitute 'Keys.Separator' in the above WrongKey function for 'Keys.OemQuestion'. Now it works perfectly. Quote If it works... don't worry, I'll fix it.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.