user3290811
user3290811

Reputation: 5

Learning VB and need to fill a variable a buttons .text thats dependent on the button pushed

My goal is to have the user able to push any button and the .text of the button to be passed into a a text box. the below is a very simplified version of what i want to achieve... i know i can have each button in its own sub however doing this will create hundreds of lines of code while if what i wish to do works, it will only be a few lines...

https://i.sstatic.net/tuF5n.png

Sub Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
TextBox1.Text = (TextBox1.Text + ??? )
End Sub

so what would i replace the ??? with to represent the .text of the button the user pushes?

(This is using VB in Visual Studios 2013)

Thank you in advance ^.^

Upvotes: 0

Views: 35

Answers (1)

Ry-
Ry-

Reputation: 224856

The sender parameter is the sender of the event. You’ll probably need to cast it before doing anything useful:

Dim button As Button = DirectCast(sender, Button)

Then you can use it:

TextBox1.Text &= button.Text

Upvotes: 2

Related Questions