Home   Cover Cover Cover Cover
 

Multiple document interface

Chap4_Ex26.cs
using System;
using System.Drawing;
using System.Windows.Forms;


class MdiForm : Form {
  private ToolBar toolBar;
    
  MdiForm (bool isMDI) {
    if(isMDI) this.IsMdiContainer = true;
    toolBar = new ToolBar();
    toolBar.Buttons.Add(new ToolBarButton("Open"));
    toolBar.Buttons.Add(new ToolBarButton("Close"));
    toolBar.ButtonClick += new ToolBarButtonClickEventHandler (this.ButtonClick);
    Controls.Add(toolBar);
  }
    
  protected void ButtonClick (Object sender, ToolBarButtonClickEventArgs e) {
      
    switch(toolBar.Buttons.IndexOf(e.Button)) {
      case 0:
        if(IsMdiContainer) {
          MdiForm newForm = new MdiForm(false);
          newForm.MdiParent = this;
          newForm.Size = new Size(100,100);
          newForm.Show();
        }
        break; 
      case 1:
        this.Close();
        break; 
    }
  }


  public static void Main(string[] argv) {
    Application.Run(new MdiForm(true));
  }
}