多个按钮处理程序 [英] Multiple Button Handler
问题描述
我有七个文本框,txtDay1到txtDay7。
我有7个命令按钮,btnExpand1到btnExpand7
当点击一个按钮时,它设置文本框的高度为200.
Private Sub btnExpand1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理btnExpand1。点击
Me.txtDisplay1.Height = 200
End Sub
我会的喜欢有一个例程来处理所有点击。也就是说,例程
应该能够分辨出哪个按钮被点击了。
我该怎么做?
谢谢
Vayse
I have seven text boxes, txtDay1 to txtDay7.
I have 7 command buttons, btnExpand1 to btnExpand7
When a button is clicked, it sets the height of the text box to 200.
Private Sub btnExpand1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExpand1.Click
Me.txtDisplay1.Height = 200
End Sub
I''d like to have one routine to handle the all clicks. That is, the routine
should be able to tell which button was clicked.
How would I do this?
Thanks
Vayse
推荐答案
使用此
在Visual Studio中,如果将光标放在Sub
声明的末尾并按空格键,则可以在
之后输入多个事件。第一个是这样的,
处理btnExpand1.Click,btnExpand2.Click,btnExpand3.click等等。
这将有效因为签名是相同的。
Use this
In Visual Studio, if you place your cursor at the end of the Sub
declaration and press the space bar, you can enter several events after
the first like this,
Handles btnExpand1.Click, btnExpand2.Click, btnExpand3.click and so on.
This will work as long as the signatures are the same.
亲爱的Vayse,
您还可以查看AddHandler。使用AddHandler,您可以将''
事件重定向到方法。
您可以将所有按钮点击事件重定向到一个方法,方法是执行
多个AddHandler调用。
请注意,此方法应该有一个sender参数,以确定单击哪个按钮
.
Michel van den Berg
" Vayse" < Va的*** @ nospam.nospam> schreef in bericht
新闻:OF **************** @ TK2MSFTNGP10.phx.gbl ...
Dear Vayse,
you could also have a look at AddHandler. With AddHandler you can ''redirect''
events to methods.
You could redirect all you button click event to one method by doing
multiple AddHandler calls.
Note that this method should have a sender parameter in order to determine
which button was clicked.
Michel van den Berg
"Vayse" <Va***@nospam.nospam> schreef in bericht
news:OF****************@TK2MSFTNGP10.phx.gbl...
我有七个文本框,txtDay1到txtDay7。
我有7个命令按钮,btnExpand1到btnExpand7
单击一个按钮时,它会将文本框的高度设置为200.
<私有子btnExpand1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理btnExpand1.Click
Me.txtDisplay1.Height = 200
我想有一个例程来处理所有点击。也就是说,
例程应该能够分辨出哪个按钮被点击了。
我该怎么做?
谢谢
Vayse
I have seven text boxes, txtDay1 to txtDay7.
I have 7 command buttons, btnExpand1 to btnExpand7
When a button is clicked, it sets the height of the text box to 200.
Private Sub btnExpand1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExpand1.Click
Me.txtDisplay1.Height = 200
End Sub
I''d like to have one routine to handle the all clicks. That is, the
routine should be able to tell which button was clicked.
How would I do this?
Thanks
Vayse
我错过了你的一些帖子,你需要这个
选择Case Sender.name
Case" btnExpand1"
txtDisplay1.Height = 200
Case" btnExpand2"
txtDisplay2.Height = 200
结束选择
I missed some of your post, you will need this
Select Case Sender.name
Case "btnExpand1"
txtDisplay1.Height = 200
Case "btnExpand2"
txtDisplay2.Height = 200
End Select
这篇关于多个按钮处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!