1. Derive your form MyForm from the System.Windows.Forms.Form.
2.Declare as minimum aSystem.ComponentModel.Container member like :
private System.ComponentModel.Container components = null;
3. Declare other controls (Menu, TextEdit, buttons, timers etc) and member variables depending on your needs.
private System.Windows.Forms.MainMenu m_MnuMain;
private System.Windows.Forms.MenuItem m_MnuConnect;
private System.Windows.Forms.OpenFileDialog m_OpenFileDialog;
private System.Windows.Forms.StatusBar m_StatusBar;
//...
4. Implement a constructor in which will create the above objects and do any initialization
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MyForm));
this.m_MnuMain = new System.Windows.Forms.MainMenu();
this.m_MnuConnect = new System.Windows.Forms.MenuItem();
this.m_OpenFileDialog = new System.Windows.Forms.OpenFileDialog();
this.m_StatusBar = new System.Windows.Forms.StatusBar();
//...
this.SuspendLayout();
// Set propoerty for each above object
// m_MnuMain
this.m_MnuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.m_MnuFile,
this.m_MnuEdit,
this.m_MnuConnect});
this.m_MnuConnect.Index = 0;
this.m_MnuConnect.Text = "&Connect";
this.m_MnuConnect.Click += new System.EventHandler(this.m_MnuConnect_Click);
//
this.m_MnuOpenFile.Enabled = false;
this.m_MnuOpenFile.Index = 3;
this.m_MnuOpenFile.Text = "&Open File...";
this.m_MnuOpenFile.Click += new System.EventHandler(this.m_MnuOpenFile_Click);
// m_StatusBar
// you should find out the right (x,y)
this.m_StatusBar.Location = new System.Drawing.Point(0, 244);
this.m_StatusBar.Name = "m_StatusBar";
this.m_StatusBar.Size = new System.Drawing.Size(728, 22);
this.m_StatusBar.TabIndex = 1;
this.m_StatusBar.Text = "Ready...";
// MyForm
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.m_StatusBar});
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.IsMdiContainer = true;
this.Menu = this.m_MnuMain;
this.Name = "MYForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "My Form";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
this.Load += new System.EventHandler(this.MyForm_Load);
//...
this.ResumeLayout(false);
5. Implement the handlers:
private void MyForm_Load(object sender, System.EventArgs e)
{
//...
}
private void m_MnuConnect_Click(object sender, System.EventArgs e)
{
//...
}
private void m_MnuOpenFile_Click(object sender, System.EventArgs e)
{
m_OpenFileDialog.Title="Select source file to open";
//...
}
private void MyForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//...
}
6. Implement Dispose(bool)
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
// cleanup here
components.Dispose();
}
}
base.Dispose( disposing );
}
7. Now you can instantiate your form like :
MyForm mf = new MyForm();
mf.Show();
etc...