Simple Question 6 to net

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

hi
in vb6 there was an option to set a button as the default action if enter is
hit, this option does not seem to be in dotnet.

I have a textbox to type in and I want the user to be able to hit the button
or hit enter/return to kick off the button action.


I have tried the following to see if I can capture the key stroke and then
act upon it, but it shows the code for normal keys but not the return key?
Private Sub txtSend_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtSend.TextChanged

MsgBox(Asc(txtSend.Text.Substring(txtSend.Text.Length - 1, 1)))
 
well this is still possible


goto the properties window of your form , look at the section "Misc" then
at the property AcceptButton select your button
now if the user presses the enter key the action below that button will be
triggered

( the CancelButton action will be triggered when the user presses the escape
button )

regards

Michel Posseth [MCP]
 
Adrian said:
hi
in vb6 there was an option to set a button as the default action if enter is
hit, this option does not seem to be in dotnet.

I have a textbox to type in and I want the user to be able to hit the button
or hit enter/return to kick off the button action.


I have tried the following to see if I can capture the key stroke and then
act upon it, but it shows the code for normal keys but not the return key?
Private Sub txtSend_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtSend.TextChanged

MsgBox(Asc(txtSend.Text.Substring(txtSend.Text.Length - 1, 1)))

try to handle the txtSend.OnKeyDown event. It'll give you what you need.

Chris
 
Hi
thanks you both as I was trying to get the enter to default only when
hit in a text box I have followed Chris's lead thus:
If e.KeyCode.Enter Then

cmdSend.PerformClick()

End If

And it works great thanks, but I have also noted the form option for future
use!



Thanks
 
Adrian said:
in vb6 there was an option to set a button as the default action if
enter is hit, this option does not seem to be in dotnet.

It's no longer on the individual Controls; it's on the containing Form
(which is more logical O.O'ly) in the form (sic) of the AcceptButton
property.
I have a textbox to type in and I want the user to be able to hit the
button or hit enter/return to kick off the button action.

That'll do it.

Beware /multi-line/ testboxes, though!
I have tried ... to see if I can capture the key stroke ... but it shows
the code for normal keys but not the return key?

There are lots of "odd" little routines (PreProcessMessage,
ProcessCmdKey, etc.) that do things like this; have a rummage
around; you'll probably find one of these that does what you want.
Perhaps more importantly, though, AcceptButton /will/ do what you
want for the moment.

HTH,
Phill W.
 
Back
Top