dotnetmonitor.com |
|
||||||||||||
| The following is how to use ToolStripPanels correctly
in an MDIParent. This is important, because due to layering and MDI limiations,
use of ToolStripContainer doesnt work well.
public Form1() { // Make Form MDI Parent this.IsMdiContainer = true;
// Add toolstrip panels ToolStripPanel tspTop = new ToolStripPanel(); ToolStripPanel tspBottom = new ToolStripPanel(); ToolStripPanel tspLeft = new ToolStripPanel(); ToolStripPanel tspRight = new ToolStripPanel();
// dock the ToolStripPanels tspTop.Dock = DockStyle.Top; tspBottom.Dock = DockStyle.Bottom; tspLeft.Dock = DockStyle.Left; tspRight.Dock = DockStyle.Right;
// add toolstrips to move around between the panels ToolStrip tsTop = new ToolStrip(); tsTop.Items.Add("Top"); tspTop.Join(tsTop);
ToolStrip tsBottom = new ToolStrip(); tsBottom.Items.Add("Bottom"); tspBottom.Join(tsBottom);
ToolStrip tsRight = new ToolStrip(); tsRight.Items.Add("Right"); tspRight.Join(tsRight);
ToolStrip tsLeft = new ToolStrip(); tsLeft.Items.Add("Left"); tspLeft.Join(tsLeft);
// add menustrip, with new window MenuStrip ms = new MenuStrip(); ToolStripMenuItem windowMenu = new ToolStripMenuItem("Window"); ToolStripMenuItem windowNewMenu = new ToolStripMenuItem("New", null, new EventHandler(windowNewMenu_Click)); windowMenu.DropDownItems.Add(windowNewMenu); ((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowImageMargin = false; ((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowCheckMargin = true;
ms.MdiWindowListItem = windowMenu;
ms.Items.Add(windowMenu); ms.Dock = DockStyle.Top;
// Form.MainMenuStrip determines merge target MainMenuStrip = ms;
// add a button to the MDIClient area Button b = new Button(); b.AutoSize = true; b.Text = "In the MDI Container";
// Add the ToolStripPanels to the form in reverse order this.Controls.Add(tspRight); this.Controls.Add(tspLeft); this.Controls.Add(tspBottom); this.Controls.Add(tspTop);
// add menustrip last - Z order! this.Controls.Add(ms);
}
void windowNewMenu_Click(object sender, EventArgs e) { Form f = new Form(); f.MdiParent = this; f.Text = "Form - " + this.MdiChildren.Length.ToString(); f.Show();
} } |
||||||||||||
|
||||||||||||