Hot File

MDI child as dialog form (MDI modal workaround)

View: 2925    Dowload: 1   Comment: 0   Post by: naruto  
Author: none   Category: Form - Instructions   Fields: Computers - Technology

9 point/10 review File has been tested

Download   mdi-child-as-dialog-form-mdi.zip (18.98 KB)

You need to Sign In to download the file mdi-child-as-dialog-form-mdi.zip
If you do not have an account then Sign up for free here

Download error   Report copyright violation

Ever had the need to block all other forms and controls when a specific form is shown as a dialog? This is a very simple workaround, for an MDI modal form.

Introduction

Ever had the need to block all other forms and controls when a specific form is shown as a dialog? This is a very simple workaround, for an MDI modal form.

Background

I was designing an MDI rich application, where I needed a dialog form showing only in the parent form, and blocking the rest of the application, until the user selected something on the dialog form.

Using the code

The code is very, very simple; just inherit the MDIParent form on your MDI parent form instead of the normal form inheritance.

 
public partial class Your_MDI_Parent_Form : MdiParent

To show a form as a dialog and block other controls, call the ShowChildDialog method on the parent form, like this:

ChildForm frm = new ChildForm();
ShowChildDialog(frm, ChildForm_DialogReturned);

And, to receive the DialogResult from the child form, use the following event receiver:

private void ChildForm_DialogReturned(object sender, DialogResultArgs e)
{
    MessageBox.Show("ChildForm returned: " + e.Result.ToString());
    ((Form)sender).Dispose();
}

Explanation of the code

The ShowChildDialog method

public void ShowChildDialog(Form frm, 
       EventHandler DialogReturnedValue)
{
    frm.MdiParent = this;
    frm.MaximizeBox = false;
    frm.FormClosed += new FormClosedEventHandler(frm_FormClosed);
    callingsender = frm;
    DialogReturning += DialogReturnedValue;
    DisableControls();
    frm.Show();
}
  1. Set the MDI parent so the form is shown within the parent.
  2. Remove the Maximize button on the child form.
  3. Add an event receiver for the Closed event on the child form; this will be used to return the dialog result from the child dialog form.
  4. callingsender is for internal use, so the code knows which form it is dealing with.
  5. Add an event receiver for the returned dialog result.
  6. Calling the DisableControls method will disable all other controls and forms in the MdiParent.
  7. Last, show the form. This will be the only one enabled.

The DisableControls method

private void DisableControls()
{
    for (int i = 0; i < this.Controls.Count; i++)
    {
        if (this.Controls[i].GetType() != typeof(MdiClient))
            this.Controls[i].Enabled = false;
    }
    foreach (Form frm in MdiChildren)
        frm.Enabled = false;
    if(callingsender != null)
        callingsender.Enabled = true;
}
  1. Loop through all the controls of the MDI parent and disable them if it not an MDI child control.
  2. Loop through all the child forms and disable them.
  3. If callingsender is not null, then enable it again.

The ForceReleaseOfControls method

public void ForceReleaseOfControls()
{
    for (int i = 0; i < this.Controls.Count; i++)
        this.Controls[i].Enabled = true;
    
    foreach (Form frm in MdiChildren)
        frm.Enabled = true;
}
  1. Loop through all the controls and enable them again.
  2. Loop through all the child forms and enable them again.

What the code does not do...

This code does not check for the pre-enabled-state of controls and forms. Therefore, it will not remember what enable state the control/form was before, and set it back to that. This can be achieved pretty simply by having a collection of keys and values. But for now, this is the code. Hope it helps those who have the same issues as I did.

Point of interest

I learnt something new about MDI applications.

History

  • 21. Dec. 2009: First post.
  • 21. Dec. 2009 (later): Updated the article with some explanation of the code.

License

This article, along with any associated source code and files, is licensed under http://www.codeproject.com/info/cpol10.aspx

MDI child as dialog form (MDI modal workaround)

MDI child as dialog form (MDI modal workaround) Posted on 21-03-2014  Ever had the need to block all other forms and controls when a specific form is shown as a dialog? This is a very simple workaround, for an MDI modal form. 0.9/10 2925

Comment:

To comment you must be logged in members.

Files with category

  • Form Management in MOSS 2007

    View: 2909    Download: 0   Comment: 0   Author: none  

    Form Management in MOSS 2007

    Category: Form - Instructions
    Fields: Other

    0/7 review
    The purpose of this document is to give an overview of Form Management in Microsoft Office SharePoint Server 2007. This article explains how to create and publish forms using Microsoft Office InfoPath 2007 in to SharePoint site.

  • Mac OS X Theme for Windows Forms

    View: 3412    Download: 2   Comment: 0   Author: none  

    Mac OS X Theme for Windows Forms

    Category: Form - Instructions
    Fields: Other

    0/9 review
    Some programmers might want to apply some themes or skins to their forms so that it will look cool, sophisticated, and attractive. I have created a Mac OS X open source theme library for everyone and the usage of it is indicated on this article.

  • Those Crazy Popups

    View: 1841    Download: 0   Comment: 0   Author: none  

    Those Crazy Popups

    Category: Form - Instructions
    Fields: Other

    0/1 review
    Ever tried to create a pop-up in ASP.NET? Well, in this article, we will see different ways to create them. We'll also see a few issues surrounding the different ways.

  • Handling .NET forms and their events in VB6 main application

    View: 3412    Download: 1   Comment: 0   Author: none  

    Handling .NET forms and their events in VB6 main application

    Category: Form - Instructions
    Fields: Other

    0/6 review
    I always wanted to post an article in CodeProject. I was always "taking" not "giving" anything back to this community and that made me feel guilty. I think its time to "give" back something useful to this community

  • Beginners’ Guide To Web Design

    View: 529    Download: 0   Comment: 0   Author: none  

    Beginners’ Guide To Web Design

    Category: Form - Instructions
    Fields: Other

    0/2 review
    If you’re a total newbie to the whole web designing business, you’ve come to the right place. Web design is a tricky thing to deal with, and with that being said there are many things that you have to keep in mind. Enumerated below are the things...

  • GraphicRiver.net – A Review

    View: 743    Download: 0   Comment: 0   Author: none  

    GraphicRiver.net – A Review

    Category: Form - Instructions
    Fields: none

    0/1 review
    Designers are always looking for resources to maximize their revenue. Whether it is a useful freelancing website, a blog or a marketplace, they never fail to entertain a designer’s desire to earn and learn, too. In this article I am going to review...

  • How to Establish a Dreamweaver Website on Localhost – EasyPhp

    View: 1075    Download: 0   Comment: 0   Author: none  

    How to Establish a Dreamweaver Website on Localhost – EasyPhp

    Category: Form - Instructions
    Fields: none

    0/4 review
    While developing a website, it is sometimes quite annoying and repetitive to edit the code in the editor and then test it on the browser, especially when working with WordPress. So, to ensure smooth workflow and faster development, we use a feature...

  • Top 15 Websites to learn Web Design and Development

    View: 775    Download: 0   Comment: 0   Author: none  

    Top 15 Websites to learn Web Design and Development

    Category: Form - Instructions
    Fields: none

    0/1 review
    People are, at all times looking to enhance their skills at Designing and Developing websites. Formal education in this field is quite rare so in this article, I’m going to share the 15 Top Websites to Learn Web Design and Development from, more...

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd