Add a button:
Button myButton = new Button();
myButton.Parent = someParent;
Same as
someParent.Controls.Add(myButton);
Now, I don't think your question was how to add event. You can only do it in your own class. You probably need to know how to add an event handler to the invocation list of the existing event instance. This is how:
myButton.Click += (sender, eventArgs) => {
DoSomethingOnClick();
};
In case you are using C# v.2, lambda form is not available, but still, use the
anonymous method using older syntax, without
type inference:
myButton.Click += delegate(object sender, System.EventArgs eventArgs) {
DoSomethingOnClick();
};
[EDIT]
In VB.NET, adding a button is the same, but adding a handler has very different syntax:
AddHandler myBitton.Click, AddressOf SomeClickHandlerMethod
Anonymous form:
AddHandler myBitton.Click, Sub()
DoSomethingOnClick()
EndSub
Sorry for the confusion about C# vs VB.NET code (resolved thanks to CPallini), but I must note that you need to understand at least some C# if you want to get help or use the work of others in .NET. More of better quality help comes in C#, which is also a standardized language, in contrast to VB.NET.
—SA