I’m not able to get a basic click listener to work.
I’ve created a base button with the (Name) of button1.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("button1 was clicked");
}
When I run the application and click my button it doesn’t fire. I’m struggling to figure this out because I’m following the guide outlined here: http://msdn.microsoft.com/en-us/library/dfty2w4e.aspx
It appears you’re missing this line
button1.Click += new EventHandler(button1_Click);, you should add this in the forms constructor.If you go through the UI designer you can just drag the button onto the UI, then double click it and it will create the listener for you; everything you have there, plus the line above in the designer file, minus the
MessageBox.Show(). This is the route I would recommend for creating all of your standard listeners.