Click here to Skip to main content
15,891,204 members
Articles / Programming Languages / C#
Article

Mdi Manager VS2003 Style

Rate me:
Please Sign up or sign in to vote.
3.67/5 (4 votes)
24 May 2007CPOL 39.2K   796   20   4
Good choice for replace default mdi
Screenshot - asMdiManager.jpg

Introduction

This Mdi control is look like VS2003, include feature TabTitle, CloseAll, MdiList but not support docking, drag n drop. Any question welcome. This is my first articles and fair english.

Background

My last application use mdi but it always flicker when use Application.EnableVisualStyle() and switch between child form. I search from the internet and found many many. Some control has a lot of code then i decided to created own mdi control(light-weight) and shared to you.

Using the code

Before use this code, ensure to compile before.
Add the control to your VS ToolBox by choose file "asWins.Forms.dll" and select "asMdiManager".

Create a new MainForm and add MainMenu and control "asMdiManager" to MainForm but not set property IsMdiContainer to true because we do not use standard feature.

For all ChildForm must be inherit from class asWins.Forms.BaseForm it has property to allow open dupplicate form.

private bool m_AllowDuplicate; 
/// 
<summary />/// Allow open more than 1 times. 
/// 
</summary />[ 
DefaultValue(false), 
Category("Appearance"), 
Description("Allow open more than 1 times.") 
] 
public bool AllowDuplicate 
{ 
    get {return m_AllowDuplicate;} 
    set {m_AllowDuplicate = value;} 
}

In MainForm when click on MenuItem to open child form in the old way we use

private void menuItem3_Click(object sender, System.EventArgs e)
{
        DummyForm frm = new DummyForm();
        frm.MdiParent = this;
    frm.Show();
}

Change to this code.
private void menuItem3_Click(object sender, System.EventArgs e)
{
        DummyForm frm = new DummyForm();
        this.asMdiManager1.AddForm(frm);
}

it very easy.

License

If you like it pls send postcard to me, see address at menu about.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Thailand Thailand
He start from web developer(asp classic) since 1997, and now use .net techonogy(c#, vb.net).

Comments and Discussions

 
Generalform.show() flicker Pin
Vincent_ws14-Aug-07 19:20
Vincent_ws14-Aug-07 19:20 
GeneralRe: form.show() flicker Pin
Marcus Deecke17-Aug-07 11:56
Marcus Deecke17-Aug-07 11:56 
GeneralRe: form.show() flicker Pin
Vincent_ws19-Aug-07 15:59
Vincent_ws19-Aug-07 15:59 
GeneralRe: form.show() flicker Pin
v# guy18-Aug-07 0:20
v# guy18-Aug-07 0:20 
Hi Vincent_ws

Sorry for wait reply, my code use panel below is procedure to add child form and show it.

///
/// Add form to MdiManager.
///

/// <param name="form" />
public void AddForm(BaseForm form)
{
if (!form.AllowDuplicate)
{
if (this.FormExists(form.Name))
{
// Debug Only
MessageBox.Show("This form not supported duplicate, AllowDuplicate=false",
form.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
form.Dispose();
return;
}
}
this.m_TabForms.ResetActiveTabForms();

// Debug Only
form.Text = form.Text + this.nFormRunning.ToString();

// Add event when closing.
form.Closing += new CancelEventHandler(form_Closing);
form.TopLevel = false;
form.TopMost = false;

form.FormBorderStyle = FormBorderStyle.None;
form.WindowState = FormWindowState.Normal;
form.StartPosition = FormStartPosition.Manual;

form.Location = new Point(0, 0);
form.Size = this.m_Content.Size;
form.Dock = DockStyle.Fill;
form.Parent = this.Content;
form.Visible = true;


// Add Tab
asTabForm tab = new asTabForm(form, nFormRunning, true, this);
this.TabForms.Add(tab);
tab.SetFormActive();

// Add Menu MdiList
this.AddMdiList(form.Text, this.nFormRunning);

// Increase running
this.nFormRunning += 1;

this.SetButtonLocation();
Invalidate(false);

// Trick event.
this.OnChildFormAdded(this, new EventArgs());
}

hope to help. Cool | :cool:

Dream it, Do it.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.