Click here to Skip to main content
15,881,844 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.4K   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.Collections;
using System.Drawing;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary ;
using System.Windows.Forms ;

/// <summary>
///    Summary description for Doc.
/// </summary>
public class MDIDoc
{
	// The document keeps track of the current pen width on
	// behalf of all views. We'd like the user interface of
	// Scribble to be such that if the user chooses the Draw
	// Thick Line command, it will apply to all views, not just
	// the view that currently has the focus.

	public int docID; // ID to display it on the view
	public ArrayList viewList = new ArrayList();
	public bool isDirty;

	
    public MDIDoc(Form1 mainWin)
    {
		isDirty= false;
		
		//Set the ID to be the current count + 1. This is so that the ID starts with 1
		docID = Form1.documentCount+1;
		//Create a view (Form) for this document
		MDIView view = new MDIView(this,mainWin);
		viewList.Add(view);		
		view.Show();				
    }

	//Save the document
	public void SaveDocument(string fileName)
	{
		try 
		{
			Stream s = File.Open(fileName,FileMode.Create);
			BinaryFormatter b = new BinaryFormatter();

			//
			// TODO
			// b.Serialize(s, ....) // add the stuff to serialize here
			//

			s.Close();			
			//Now that the doc is saved, its no more dirty
			isDirty = false;
		}
	
		catch(Exception ex)
		{
			MessageBox.Show(ex.ToString());
		}
	}

	//Open the document
	public void OpenDocument(string fileName)
	{
		try 
		{
			Stream s = File.Open(fileName,FileMode.Open);
			BinaryFormatter b = new BinaryFormatter();

			// 
			// TODO
			// ... = b.Deserialize(s); // add the deserialization handling here
			//
			s.Close();						
		}	
		catch(Exception ex)
		{
			MessageBox.Show(ex.ToString());
		}
	}	

	//Updates all the views of the document with the new data
	public void UpdateAllViews(MDIView sender)
	{		
		MDIView view;
		
		for(int i=0; i < viewList.Count ; i++)
		{
			view = (MDIView)viewList[i];	

			if(view.Equals(sender))
				continue;

			// if required, invalidate the entire region but remove the comment in the following line
			//view.Invalidate();

			view.Update();
		}			
	}

	// Deletes the contents of the document
	public void DeleteContents()
	{
		UpdateAllViews(null); // sync everything
	}

}
}

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