📄 sampleform.cs
字号:
// *****************************************************************************
//
// (c) Crownwood Consulting Limited 2002
// All rights reserved. The software and associated documentation
// supplied hereunder are the proprietary information of Crownwood Consulting
// Limited, Haxey, North Lincolnshire, England and are supplied subject to
// licence terms.
//
// Magic Version 1.7 www.dotnetmagic.com
// *****************************************************************************
using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Crownwood.Magic.Menus;
using Crownwood.Magic.Common;
using Crownwood.Magic.Controls;
using Crownwood.Magic.Docking;
using Crownwood.Magic.Win32;
namespace SampleTabbedGroups
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class SampleForm : System.Windows.Forms.Form
{
private int _count = 1;
private int _image = -1;
private RichTextBox _global;
private DockingManager _manager;
private Crownwood.Magic.Menus.MenuControl menuControl1;
private System.Windows.Forms.StatusBar statusBar1;
private Crownwood.Magic.Controls.TabControl tabControl1;
private Crownwood.Magic.Controls.TabPage tabPage1;
private Crownwood.Magic.Controls.TabPage tabPage2;
private Crownwood.Magic.Controls.TabPage tabPage3;
private Crownwood.Magic.Controls.TabbedGroups tabbedGroups1;
private Crownwood.Magic.Controls.TabbedGroups tabbedGroups2;
private Crownwood.Magic.Controls.TabbedGroups tabbedGroups3;
private System.Windows.Forms.ImageList mainTabs;
private System.Windows.Forms.ImageList groupTabs;
private System.ComponentModel.IContainer components;
public SampleForm()
{
// Required for Windows Form Designer support
InitializeComponent();
// Create menu options
CreateMenu();
// Define the docking windows
CreateDockingWindows();
// Create some initial tab pages inside each group
CreateInitialPages();
}
protected void CreateMenu()
{
// Create top level commands
MenuCommand pages = CreatePages();
MenuCommand persist = CreatePersistence();
MenuCommand tabsMode = CreateTabsMode();
// Add top level commands
menuControl1.MenuCommands.AddRange(new MenuCommand[] {pages, persist, tabsMode});
}
protected MenuCommand CreatePages()
{
MenuCommand pages = new MenuCommand("Pages");
// Create pages sub commands
MenuCommand add = new MenuCommand("Add", new EventHandler(OnAddPage));
MenuCommand remove = new MenuCommand("Remove", new EventHandler(OnRemovePage));
pages.MenuCommands.AddRange(new MenuCommand[] {add, remove});
// Enable/disable the remove option as appropriate
pages.PopupStart += new CommandHandler(OnPages);
return pages;
}
protected MenuCommand CreatePersistence()
{
MenuCommand persist = new MenuCommand("Persistence");
// Create Persistence sub commands
MenuCommand saveG1 = new MenuCommand("Save Group1", new EventHandler(OnSaveG1));
MenuCommand loadG1 = new MenuCommand("Load Group1", new EventHandler(OnLoadG1));
MenuCommand sep1 = new MenuCommand("-");
MenuCommand saveG2 = new MenuCommand("Save Group2", new EventHandler(OnSaveG2));
MenuCommand loadG2 = new MenuCommand("Load Group2", new EventHandler(OnLoadG2));
MenuCommand sep2 = new MenuCommand("-");
MenuCommand saveG3 = new MenuCommand("Save Group3", new EventHandler(OnSaveG3));
MenuCommand loadG3 = new MenuCommand("Load Group3", new EventHandler(OnLoadG3));
persist.MenuCommands.AddRange(new MenuCommand[] {saveG1, loadG1, sep1,
saveG2, loadG2, sep2,
saveG3, loadG3});
return persist;
}
protected MenuCommand CreateTabsMode()
{
MenuCommand tabsMode = new MenuCommand("DisplayMode");
// Create modes sub commands
MenuCommand hideAll = new MenuCommand("Hide All", new EventHandler(OnHideAll));
MenuCommand showAll = new MenuCommand("Show All", new EventHandler(OnShowAll));
MenuCommand showActiveLeaf = new MenuCommand("Show Active Leaf", new EventHandler(OnShowActiveLeaf));
MenuCommand showMouseOver = new MenuCommand("Show Mouse Over", new EventHandler(OnShowMouseOver));
MenuCommand showActiveAndMouseOver = new MenuCommand("Show Active And Mouse Over", new EventHandler(OnShowActiveAndMouseOver));
tabsMode.MenuCommands.AddRange(new MenuCommand[] {hideAll, showAll, showActiveLeaf,
showMouseOver, showActiveAndMouseOver});
// Set correct check mark when menu opened
tabsMode.PopupStart += new CommandHandler(OnDisplayMode);
return tabsMode;
}
protected void CreateDockingWindows()
{
// Create the docking manager instance
_manager = new DockingManager(this, VisualStyle.IDE);
// Define innner/outer controls for correct docking operation
_manager.InnerControl = tabControl1;
_manager.OuterControl = statusBar1;
// Create the tree control
TreeView tv = new DragTree();
tv.Nodes.Add(new TreeNode("First"));
tv.Nodes.Add(new TreeNode("Second"));
tv.Nodes.Add(new TreeNode("Third"));
tv.Nodes.Add(new TreeNode("Fourth"));
// Create a rich text box for the second content
_global = new RichTextBox();
// Create content instances
Content c1 = _manager.Contents.Add(tv, "TreeView");
Content c2 = _manager.Contents.Add(_global, "Another Window");
// Add to the display on the left hand side
WindowContent wc = _manager.AddContentWithState(c1, State.DockLeft);
// Add at the bottom of the same column
_manager.AddContentToZone(c2, wc.ParentZone, 1);
}
protected void CreateInitialPages()
{
CreateInitialPagesGroup1();
CreateInitialPagesGroup2();
CreateInitialPagesGroup3();
}
protected void CreateInitialPagesGroup1()
{
// Access the default leaf group
TabGroupLeaf tgl = tabbedGroups1.RootSequence[0] as TabGroupLeaf;
// Create two pages for the leaf
Crownwood.Magic.Controls.TabPage tp1 = new Crownwood.Magic.Controls.TabPage("Page" + _count++, new RichTextBox(), NextImage());
Crownwood.Magic.Controls.TabPage tp2 = new Crownwood.Magic.Controls.TabPage("Page" + _count++, new RichTextBox(), NextImage());
// Add a two pages to the leaf
tgl.TabPages.Add(tp1);
tgl.TabPages.Add(tp2);
}
protected void CreateInitialPagesGroup2()
{
// Access the default leaf group
TabGroupLeaf tgl1 = tabbedGroups2.RootSequence[0] as TabGroupLeaf;
// Add a new leaf group in the same sequence
TabGroupLeaf tgl2 = tabbedGroups2.RootSequence.AddNewLeaf();
// Add a two pages to the leaf
tgl1.TabPages.Add(NewTabPage());
tgl2.TabPages.Add(NewTabPage());
}
protected void CreateInitialPagesGroup3()
{
// Change direction to opposite
tabbedGroups3.RootSequence.Direction = Direction.Vertical;
// Access the default leaf group
TabGroupLeaf tgl1 = tabbedGroups3.RootSequence[0] as TabGroupLeaf;
// Add a new leaf group in the same sequence
TabGroupLeaf tgl2 = tabbedGroups3.RootSequence.AddNewLeaf();
// Add a two pages to the leaf
tgl1.TabPages.Add(NewTabPage());
tgl2.TabPages.Add(NewTabPage());
}
protected int NextImage()
{
_image = ++_image % 8;
return _image;
}
protected Crownwood.Magic.Controls.TabPage NewTabPage()
{
return new Crownwood.Magic.Controls.TabPage("Page" + _count++, new RichTextBox(), NextImage());
}
protected void OnPages(MenuCommand pages)
{
Crownwood.Magic.Controls.TabControl tc = null;
// Find the active tab control in the selected group
if (tabControl1.SelectedIndex == 0)
{
if (tabbedGroups1.ActiveLeaf != null)
tc = tabbedGroups1.ActiveLeaf.GroupControl as Crownwood.Magic.Controls.TabControl;
}
else
{
if (tabControl1.SelectedIndex == 1)
{
if (tabbedGroups2.ActiveLeaf != null)
tc = tabbedGroups2.ActiveLeaf.GroupControl as Crownwood.Magic.Controls.TabControl;
}
else
{
if (tabbedGroups3.ActiveLeaf != null)
tc = tabbedGroups3.ActiveLeaf.GroupControl as Crownwood.Magic.Controls.TabControl;
}
}
// Did we find a current tab control?
if ((tc != null) && (tc.SelectedTab != null))
pages.MenuCommands[1].Enabled = true;
else
pages.MenuCommands[1].Enabled = false;
}
protected void OnAddPage(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -