这里我有一个代码,允许我在面板中获取每个按钮控件的所有文本,并将它们用作RichTextBox
的输入,但是有一个问题。
for each
按钮我希望该按钮打印按钮的文本出现问题。
我仍然是vb的新手......
这是代码。
Dim btn As Button
For Each btn In panel3.Controls
'here i should have some soft of if statement to check if a btn is clicked
Msgbox (btn.Text) ' shows the text of the button ' should be in the if statement
Next
答案 0 :(得分:0)
然后使用按钮的click事件将文本追加到richTextBox。
示例:
Private Sub btn_click(sender As Object, e As EventArgs)
'since each button uses this event we need to cast the sender
'object back to a button to get it's properties
richtextbox1.Text &= DirectCast(sender, Button).Text
End Sub
'set the click event for all button to the same event
Private Sub form_Load(sender As Object, e As EventArgs) Handles Me.Load
For Each btn In panel3.Controls
Addhandler btn.Click, AddressOf btn_click
Next
End Sub