In this article, we will learn how to add buttons in WinForm. We can add a button control in the design view, or you can dynamically add button controls in your code. The following code shows how to add a button control in the WinForm.
Using system.componentmodel; using system.drawing;
public class MenuTest: Form {private MainMenu mainMenu; private ContextMenu popUpMenu; public MenuTest () {mainMenu = new MainMenu (); popUpMenu = new ContextMenu (); popUpMenu.MenuItems.Add ( "Hello", new EventHandler (pop_Clicked)); this.ContextMenu = popUpMenu; MenuItem File = mainMenu.MenuItems.Add ( "& File"); File .MenuItems.Add (new MenuItem ( "& New", new EventHandler (this.FileNew_clicked), Shortcut.CtrlN)); File .MenuItems .Add (new MenuItem ( "& Open", new EventHandler (this.FileOpen_clicked), Shortcut.CtrlO)); File .MenuItems.Add (new MenuItem ( "& Exit", new EventHandler (this.FileExit_clicked), Shortcut.CtrlX)) This.Menu = mainmenu; menuItem About = mainmenu.Menuitems.Add ("& About"); About.Menuitems.Add (New Menuitem ("& About", New EventHandler (this.about_clicked), Shortcut.ctrla); this. Menu = mainmenu; mainmenu.getform (). Backcolor = color.indigo;