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

C# SDI/MDI Application Wizards

Rate me:
Please Sign up or sign in to vote.
3.50/5 (28 votes)
30 Nov 20038 min read 226.8K   2.7K   60  
Useful project templates for C# document-centric applications
In this article, I'll show what is brought in the zip files, how to install the application wizard, the meaning of SDI/MDI and how it was built
//Copyright (C) 2000 Microsoft Corporation.  All rights reserved.

//This source code is intended only as a supplement to Microsoft
//Development Tools and/or on-line documentation.  See these other
//materials for detailed information regarding Microsoft code samples.

//THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//PARTICULAR PURPOSE.

namespace MDIApp
{
using System;
using System.IO ;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;


/// <summary>
///    Summary description for Form2.
/// </summary>
public class MDIView : System.Windows.Forms.Form
{
    /// <summary> 
    ///    Required designer variable
    /// </summary>
    private System.ComponentModel.Container components;
	private MDIDoc myDoc;
	private Form1 mainWin;

    public MDIView(MDIDoc doc,Form1 parent)
    {
		//
        // Required for Win Form Designer support
        //
        InitializeComponent();
		this.myDoc  = doc;
		this.MdiParent = parent; //Make this view Mdi child of the main window
		mainWin = parent;	
		this.Text = "MDIDoc"+ doc.docID.ToString() + ":" + doc.viewList.Count.ToString();
	
    }

    /// <summary>
    ///    Clean up any resources being used
    /// </summary>
	protected override void Dispose( bool disposing )
	{
		if( disposing )
		{
			if (components != null) 
			{
				components.Dispose();
			}
		}
		base.Dispose( disposing );
	}

    /// <summary>
    ///    Required method for Designer support - do not modify
    ///    the contents of this method with the code editor
    /// </summary>
    private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		this.Text = "MDIDoc";
		this.BackColor  = Color.White;
		this.Paint += new PaintEventHandler (PaintHandler);
		this.Closing  += new CancelEventHandler (ClosingHandler);
		this.Closed  += new EventHandler (ClosedHandler);

		//@design this.TrayLargeIcon = true;
		//@design this.TrayHeight = 0;
			
	}

	private void PaintHandler(Object sender, PaintEventArgs e)
	{
		Rectangle rectClip = e.ClipRectangle;

		// TODO
		// add graphic commands here, for instance e.Graphics....
		//
	}

	public void ClosingHandler(Object sender, CancelEventArgs e)
	{
		if(myDoc.isDirty && myDoc.viewList.Count == 1)
		{
			DialogResult save = MessageBox.Show("Do you want to Save changes ?","MDIApp",MessageBoxButtons.YesNoCancel);
			if(save == DialogResult.Yes)
			{
				String fileExtension = Form1.fileExtension;

				SaveFileDialog saveDlg = new SaveFileDialog();
				saveDlg.Filter = "MDI Files (*"+fileExtension+")|*"+fileExtension+"|All Files (*.*)|*.*";
				saveDlg.DefaultExt = fileExtension;
				DialogResult res = saveDlg.ShowDialog ();
				
				if(res == DialogResult.OK)
				{
					myDoc.SaveDocument(saveDlg.FileName);	
					myDoc.viewList.Remove(this);
					this.MdiParent=null;// remove this view(child) from the parent list
				}
				else if(res == DialogResult.Cancel)
					e.Cancel = true;
					
			}
				
			else if(save == DialogResult.Cancel)
					e.Cancel = true; //If user selected 'Cancel',don't close the form
			
			else if(save == DialogResult.No)
			{
				myDoc.viewList.Remove(this);				
			}				
		}
		else
		{
			myDoc.viewList.Remove(this);				
		}		
	}

	public void ClosedHandler(Object sender,EventArgs e)
	{		
		//If there are no child views, then disable menu and toolbar items
		if(mainWin.MdiChildren.Length   == 0 )
			mainWin.DisableItems();					
	}
	
	public MDIDoc GetDocument()
	{
		return myDoc;
	}	

}
}

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.


Written By
France France
Addicted to reverse engineering. At work, I am developing business intelligence software in a team of smart people (independent software vendor).

Need a fast Excel generation component? Try xlsgen.

Comments and Discussions