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 SDIApp
{
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 SDIView : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable
/// </summary>
private System.ComponentModel.Container components;
private SDIDoc myDoc;
private Form1 mainWin;
public SDIView(SDIDoc 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 = "SDIDoc";
}
/// <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()
{
//
// SDIView
//
this.components = new System.ComponentModel.Container();
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(292, 273);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SDIView";
this.Text = "SDIDoc";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Closing += new System.ComponentModel.CancelEventHandler(this.ClosingHandler);
this.Closed += new System.EventHandler(this.ClosedHandler);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.PaintHandler);
}
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 ?","SDIApp",MessageBoxButtons.YesNoCancel);
if(save == DialogResult.Yes)
{
String fileExtension = Form1.fileExtension;
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.Filter = "SDI 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)
{
RemoveView();
}
}
else
{
RemoveView();
}
}
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 SDIDoc GetDocument()
{
return myDoc;
}
public void RemoveView()
{
myDoc.viewList.Remove(this);
}
}
}
|
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.
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.