|
-
Sep 21st, 2003, 09:29 PM
#1
Thread Starter
Addicted Member
mdi application question
I'm sure this isn't very difficult I'm just not sure how to do it.
In most mdi applications you see a window menu an in this menu you have Tile, Cascade, Arrange Icons, and also "a list of all the child windows"
What I'm getting to is how to I make it list all the child windows in the window menu an have the click event to make that window active
-
Sep 22nd, 2003, 04:46 AM
#2
Lively Member
Create a new windows application project and replace all the code in the default Form1 that is created with code below. It should be a good starting point
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private int _counter = 0;
private System.Windows.Forms.MainMenu _mnuFile;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem _mnuAddWindow;
private System.Windows.Forms.MenuItem _mnuWindow;
private System.Windows.Forms.MenuItem _mnuWindowSep;
private System.Windows.Forms.MenuItem _mnuCascade;
private System.Windows.Forms.MenuItem _mnuTileHorizontal;
private System.Windows.Forms.MenuItem _mnuTileVertical;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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()
{
this._mnuFile = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this._mnuAddWindow = new System.Windows.Forms.MenuItem();
this._mnuWindow = new System.Windows.Forms.MenuItem();
this._mnuWindowSep = new System.Windows.Forms.MenuItem();
this._mnuCascade = new System.Windows.Forms.MenuItem();
this._mnuTileHorizontal = new System.Windows.Forms.MenuItem();
this._mnuTileVertical = new System.Windows.Forms.MenuItem();
//
// _mnuFile
//
this._mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this._mnuWindow});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this._mnuAddWindow});
this.menuItem1.Text = "File";
//
// _mnuAddWindow
//
this._mnuAddWindow.Index = 0;
this._mnuAddWindow.Text = "Add Window";
this._mnuAddWindow.Click += new System.EventHandler(this._mnuAddWindow_Click);
//
// _mnuWindow
//
this._mnuWindow.Index = 1;
this._mnuWindow.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this._mnuCascade,
this._mnuTileHorizontal,
this._mnuTileVertical,
this._mnuWindowSep});
this._mnuWindow.Text = "Window";
//
// _mnuWindowSep
//
this._mnuWindowSep.Index = 3;
this._mnuWindowSep.Text = "-";
//
// _mnuCascade
//
this._mnuCascade.Index = 0;
this._mnuCascade.Text = "Cascade";
this._mnuCascade.Click += new System.EventHandler(this._mnuCascade_Click);
//
// _mnuTileHorizontal
//
this._mnuTileHorizontal.Index = 1;
this._mnuTileHorizontal.Text = "Tile Horizontal";
this._mnuTileHorizontal.Click += new System.EventHandler(this._mnuTileHorizontal_Click);
//
// _mnuTileVertical
//
this._mnuTileVertical.Index = 2;
this._mnuTileVertical.Text = "Tile Vertical";
this._mnuTileVertical.Click += new System.EventHandler(this._mnuTileVertical_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(356, 326);
this.IsMdiContainer = true;
this.Menu = this._mnuFile;
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void _mnuAddWindow_Click(object sender, System.EventArgs e)
{
_counter++;
string caption = "Form " + _counter;
Form form = new Form();
form.Text = caption;
form.MdiParent = this;
form.Show();
_mnuWindow.MenuItems.Add(caption , new System.EventHandler(this._mnuWindowItem_Click));
}
private void _mnuCascade_Click(object sender, System.EventArgs e)
{
this.LayoutMdi(MdiLayout.Cascade);
}
private void _mnuTileHorizontal_Click(object sender, System.EventArgs e)
{
this.LayoutMdi(MdiLayout.TileHorizontal);
}
private void _mnuTileVertical_Click(object sender, System.EventArgs e)
{
this.LayoutMdi(MdiLayout.TileVertical);
}
private void _mnuWindowItem_Click(object sender, System.EventArgs e)
{
MenuItem item = (MenuItem)sender;
string formCaption = item.Text;
foreach(Form f in this.MdiChildren)
{
if (f.Text.Equals(formCaption))
{
f.BringToFront();
break;
}
}
}
}
}
-
Sep 22nd, 2003, 06:01 PM
#3
Thread Starter
Addicted Member
this is what i was looking for
this.mnuWindows.MdiList = true;
Last edited by Tewl; Sep 22nd, 2003 at 10:19 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|