You need an event handler which will fire when the button is clicked.
Here is a quick way -
var button = new Button();
button.Text = "my button";
this.Controls.Add(button);
button.Click += (sender, args) =>
{
MessageBox.Show("Some stuff");
Close();
};
But it would be better to understand a bit more about buttons, events, etc.
If you use the visual studio UI to create a button and double click the button in design mode, this will create your event and hook it up for you. You can then go to the designer code (the default will be Form1.Designer.cs) where you will find the event:
this.button1.Click += new System.EventHandler(this.button1_Click);
You will also see a LOT of other information setup for the button, such as location, etc. - which will help you create one the way you want and will improve your understanding of creating UI elements. E.g. a default button gives this on my 2012 machine:
this.button1.Location = new System.Drawing.Point(128, 214);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
As for closing the Form, it is as easy as putting Close(); within your event handler:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("some text");
Close();
}