Re: MDI (C#)
От: oleg2406rsdn Россия  
Дата: 27.10.03 08:56
Оценка:
Вот и Mdi — без скролбаров на главной форме
using System;
using System.Drawing; 
using System.Windows.Forms;

class MyForm: Form
{
    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.MenuItem menuItem2;
    private System.Windows.Forms.MenuItem menuItem3;
    private System.Windows.Forms.MenuItem menuItem4;

    public MyForm()
    {
        this.Text="Главная Форма";
        this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

        IsMdiContainer = true;

        InitializeComponent();

     } 
    static void Main()

      {
          Application.Run(new MyForm());

      }

    private void InitializeComponent()
    {
        this.mainMenu1 = new System.Windows.Forms.MainMenu();
        this.menuItem1 = new System.Windows.Forms.MenuItem();
        this.menuItem2 = new System.Windows.Forms.MenuItem();
        this.menuItem4 = new System.Windows.Forms.MenuItem();
        this.menuItem3 = new System.Windows.Forms.MenuItem();
        // 
        // mainMenu1
        // 
        this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                  this.menuItem1});
        // 
        // menuItem1
        // 
        this.menuItem1.Index = 0;
        this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                  this.menuItem2,
                                                                                  this.menuItem4,
                                                                                  this.menuItem3});
        this.menuItem1.Text = "Main";
        // 
        // menuItem2
        // 
        this.menuItem2.Index = 0;
        this.menuItem2.Text = "AddForm";
        this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
        // 
        // menuItem4
        // 
        this.menuItem4.Index = 1;
        this.menuItem4.Text = "CloseForm";
        this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
        // 
        // menuItem3
        // 
        this.menuItem3.Index = 2;
        this.menuItem3.Text = "Exit";
        this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
        // 
        // MyForm
        // 
        AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        ClientSize = new System.Drawing.Size(408, 241);
        this.Menu = this.mainMenu1;
        Name = "MyForm";

    }

    private void menuItem2_Click(object sender, System.EventArgs e)
    {
        //Находим MDIClient'a

        foreach(Control control in Controls)
            if (control is MdiClient)
                new MyNativeWindow(control);  
        
        Form form = new Form();
        form.Text = "НЕ Главная форма!";
        form.WindowState = System.Windows.Forms.FormWindowState.Normal;
        form.MdiParent = this;
        form.Show();
    }

    private void menuItem3_Click(object sender, System.EventArgs e)
    {
        Close();
    }

    private void menuItem4_Click(object sender, System.EventArgs e)
    {
     this.ActiveMdiChild.Close();
    } 

    class MyNativeWindow: NativeWindow

    {

        public MyNativeWindow(Control control)
        {

            AssignHandle(control.Handle);
            control.HandleDestroyed += new EventHandler(OnHandleDestroyed);

        } 
   
        void OnHandleDestroyed(object sender, EventArgs e)
        {
            ReleaseHandle();
        }  
   
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x3F)
                return;
            base.WndProc(ref m);
        }
    }
}

Не мое, автор —
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.