Using Ribbon wtih MDI (Multi Document Interface)


The following guide will show how to apply this ribbon with an MDI (Multi Document Interface) enabled WinForm.

Note: In previous version of Ribbon, inheritance of RibbonForm is not supported well with MDI Enabled WinForm. This problem is solved in released version of 10 May 2013.

Sample codes for VB.NET available at Downloads section.

mdi00.png

Start

1. Lets design a ribbon winform something like this as example. In the properties window, set IsMdiContainer to True.

mdi01.png

2. Create another simple another form that will be loaded into the MDI Container of MainForm.

mdi02.png

3. At code behind of Form1, add in the below codes:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.ControlBox = false;
        this.WindowState = FormWindowState.Maximized;
        this.BringToFront();
    }
}  
4. At code behind of MainForm, create the click events for RibbonButton at MainForm:

Note: In previous version of Ribbon, inheritance of RibbonForm is not supported well with MDI Enabled WinForm. This problem is solved in released version of 10 May 2013.
public partial class MainForm : RibbonForm
{
    public MainForm()
    {
        InitializeComponent();
    }

    private void ribbonButton_Form1_Click(object sender, EventArgs e)
    {
        // Load Form1
    }

    private void ribbonButton_Close_Click(object sender, EventArgs e)
    {
        // Close All Forms
    }
}  
5. Codes for loading Form1 into MDI:
private void ribbonButton_Form1_Click(object sender, EventArgs e)
{
    foreach (Form f in this.MdiChildren)
    {
        if (f.GetType() == typeof(Form1))
        {
            f.Activate();
            return;
        }
    }
    Form form1 = new Form1();
    form1.MdiParent = this;
    form1.Show();
} 
6. Codes for closing all opened form in MDI:
private void ribbonButton_Close_Click(object sender, EventArgs e)
{
    while (this.ActiveMdiChild != null)
    {
        this.ActiveMdiChild.Close();
    }
} 
7. That's it. Enjoy.

Last edited May 16, 2013 at 12:59 PM by adriancs, version 5

Comments

vishnoor Nov 7, 2015 at 12:16 PM 
Use a generic function to display MDI Child
<code>
internal void DisplayForm<T>() where T : Form
{
foreach (Form f in this.MdiChildren)
{
if (f.GetType() == typeof(T))
{
f.Activate();
return;
}
}
T form = Activator.CreateInstance<T>();
form.MdiParent = this;
form.Show();
}
</code>

private void cmdBTNew_Click(object sender, EventArgs e)
{

DisplayForm<ManageVehicle>();

}

ivex001 May 1, 2014 at 10:44 PM 
yes the buttons (Maximize Minimize and Close) doesn't show up when you maximize your child form. You have any work around on that??

hyperpro Dec 23, 2013 at 9:10 PM 
Thank you for this fancy library!
Please fix the MDI min/max/restore button if you can. These buttons make it easier to handle MDI windows. Right now, I have to create temporary buttons for the users to switch between MDI windows.

EngAbbas22 May 14, 2013 at 7:47 AM 
Prince.