views:

251

answers:

1

I've got a basic VB.net 2.0 application together in VisualStudio 2005.

Within a form, I've tied [enter] in several text boxes to a button. What I'd like to do is "press" the button from getField_KeyDown() to give the user a visual indication of what's happening.

With the code below, the button click work is done but the button's look doesn't change and the user is left without feedback.

Private Sub getField_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtGetKey.KeyDown
 If e.KeyCode = Keys.Enter Then
  e.Handled = True
  Call btnGet.PerformClick()
 End If
End Sub

How can I make the button looked pressed while the btnGet.PerformClick() work is being done?

+1  A: 

You want to set the FlatStyle of the button. So your code will look like this:

Private Sub getField_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtGetKey.KeyDown
    If e.KeyCode = Keys.Enter Then
        e.Handled = True
        btnGet.FlatStyle = FlatStyle.Flat
    End If
End Sub

This will change the button appearance - Don't forget to change it back to FlatStyle.Standard

Gavin Miller
I swear I tried that before posting the question and it wasn't working. It does now, of course. Thanks.
aczarnowski