- This topic explains how to get button click event in C#.
- Here you can get other button click event to another button in C#.
- Tools needed: Button1 (Button1), Button2 (Button2). Add below code inside the Button1 click event.
|
1 2 |
// to get button1 events this.button1_Click(null, null); |
- When we click the button two we get the click event of button 1 using C# programming.
System.Object Class – How to get button click event in C#
- Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes.
- This is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy.
- Syntax
|
1 2 3 4 |
[SerializableAttribute] [ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.AutoDual)] public class Object |
System.EventArgs Class – How to get button click event in C#
- Represents the base class for classes that contain event data, and provides a value to use for events that do not include event data.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
- Syntax
|
1 2 3 |
[SerializableAttribute] [ComVisibleAttribute(true)] public class EventArgs |
Button.Click Event – How to get button click event in C#
- Click event occurs when the Button control is clicked.
- The Click event is raised when the Button control is clicked.
- This event is commonly used when no command name is associated with the Button control
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
- Syntax
|
1 2 |
// Declaration public event EventHandler Click; |
How to get button click event in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { // to get button1 events this.button1_Click(null, null); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Event from Button1"); } private void Form1_Load(object sender, EventArgs e) { } } } |
How to get button click event in C#






