You may also like the below topics.
- Move or Add Multiple Selected Items Between ListBox Controls (C# & VB.NET)
- Remove Password/ Decrypt Excel Using C#, VB.Net in Windows Application
- Verify if an Excel File is Password Protected/Encrypted in C#, VB.Net
- C# Password Encryption and Decryption Using Secret Key Explained
- How to Transfer ListBox Items to Another ListBox in C# and VB.NET
Now for this article first we will create a new windows application and add a form. In this form we will add few label and button controls to demonstrate the example.
Now we will generate click event of button as shown in below code. In this code I have added code which I will attach to button 1 and button 2. As per object or button text I have captured the text value and displayed.
C#.Net
public Form3()
{
InitializeComponent();
button1.Click += new System.EventHandler(button1_Click);
button2.Click += new System.EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
lblButtonValue.Text = $"{button.Text}";
}
VB.Net
Public Sub New()
InitializeComponent()
AddHandler button1.Click, New System.EventHandler(AddressOf button1_Click)
AddHandler button2.Click, New System.EventHandler(AddressOf button1_Click)
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim button As Button = CType(sender, Button)
lblButtonValue.Text = $"{button.Text}"
End Sub
