Click here to Skip to main content
15,895,793 members
Articles / Desktop Programming / Windows Forms

MDI child as dialog form (MDI modal workaround)

Rate me:
Please Sign up or sign in to vote.
4.05/5 (14 votes)
21 Dec 2009CPOL2 min read 86.8K   3.5K   25  
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.
namespace MdiShowChildDialog
{
    partial class FrmMain
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.tsbNormChild = new System.Windows.Forms.ToolStripButton();
            this.tsbDialogChild = new System.Windows.Forms.ToolStripButton();
            this.toolStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // toolStrip1
            // 
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.tsbNormChild,
            this.tsbDialogChild});
            this.toolStrip1.Location = new System.Drawing.Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(550, 25);
            this.toolStrip1.TabIndex = 1;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // tsbNormChild
            // 
            this.tsbNormChild.Image = ((System.Drawing.Image)(resources.GetObject("tsbNormChild.Image")));
            this.tsbNormChild.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tsbNormChild.Name = "tsbNormChild";
            this.tsbNormChild.Size = new System.Drawing.Size(166, 22);
            this.tsbNormChild.Text = "Create Normal Child Form";
            this.tsbNormChild.Click += new System.EventHandler(this.tsbNormChild_Click);
            // 
            // tsbDialogChild
            // 
            this.tsbDialogChild.Image = ((System.Drawing.Image)(resources.GetObject("tsbDialogChild.Image")));
            this.tsbDialogChild.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tsbDialogChild.Name = "tsbDialogChild";
            this.tsbDialogChild.Size = new System.Drawing.Size(160, 22);
            this.tsbDialogChild.Text = "Create Dialog Child Form";
            this.tsbDialogChild.Click += new System.EventHandler(this.tsbDialogChild_Click);
            // 
            // FrmMain
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(550, 307);
            this.Controls.Add(this.toolStrip1);
            this.Name = "FrmMain";
            this.Text = "Demo MDI child dialog Form by Paw Jershauge";
            this.Controls.SetChildIndex(this.toolStrip1, 0);
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.ToolStrip toolStrip1;
        private System.Windows.Forms.ToolStripButton tsbNormChild;
        private System.Windows.Forms.ToolStripButton tsbDialogChild;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer
Denmark Denmark

Comments and Discussions