0

在这里,我有一个代码,允许我获取面板中每个按钮控件的所有文本并将它们用作 a 的输入,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
4

1 回答 1

0

然后使用按钮的单击事件将文本附加到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
于 2013-06-14T20:03:27.780 回答