使 VB.net winform 按钮看起来被隐藏的代码按下 [英] Making a VB.net winform button look pressed from code behind
问题描述
我在 VisualStudio 2005 中有一个基本的 VB.net 2.0 应用程序.
I've got a basic VB.net 2.0 application together in VisualStudio 2005.
在一个表单中,我将几个文本框中的 [enter] 绑定到一个按钮.我想要做的是按下"getField_KeyDown()
中的按钮,让用户直观地了解正在发生的事情.
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
如何在 btnGet.PerformClick()
工作完成时让按钮看起来被按下?
How can I make the button looked pressed while the btnGet.PerformClick()
work is being done?
推荐答案
您要设置按钮的 FlatStyle
.所以你的代码看起来像这样:
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
这将改变按钮外观 - 不要忘记将其改回 FlatStyle.Standard
This will change the button appearance - Don't forget to change it back to FlatStyle.Standard
这篇关于使 VB.net winform 按钮看起来被隐藏的代码按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!