📄 samplemenus.cs
字号:
{
int count = mc.MenuCommands.Count;
// Did the OnTopMenuStart add any entries?
if (count >= 10)
{
// Remove all the extras
for(int index = 10; index < count; index++)
mc.MenuCommands.RemoveAt(10);
}
}
protected void OnChildSelect(object sender, EventArgs e)
{
MenuCommand childCommand = sender as MenuCommand;
// Get name of the window to activate
string name = childCommand.Text;
// Get collectiom of Mdi child windows
Form[] children = this.MdiChildren;
foreach(Form f in children)
{
// Aha...found it
if (f.Text == name)
{
f.Activate();
break;
}
}
OnMenuItemSelected("ChildSelected");
}
protected void OnYesAnimateSelected(object sender, EventArgs e)
{
_topMenu.Animate = Animate.Yes;
OnMenuItemSelected("Yes - Animate");
}
protected void OnYesAnimateUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.Animate == Animate.Yes);
}
protected void OnNoAnimateSelected(object sender, EventArgs e)
{
_topMenu.Animate = Animate.No;
OnMenuItemSelected("No - Animate");
}
protected void OnNoAnimateUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.Animate == Animate.No);
}
protected void OnSystemAnimateSelected(object sender, EventArgs e)
{
_topMenu.Animate = Animate.System;
OnMenuItemSelected("System - Animate");
}
protected void OnSystemAnimateUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.Animate == Animate.System);
}
protected void On100Selected(object sender, EventArgs e)
{
_topMenu.AnimateTime = 100;
OnMenuItemSelected("100ms - AnimateTime");
}
protected void On100Update(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateTime == 100);
}
protected void On250Selected(object sender, EventArgs e)
{
_topMenu.AnimateTime = 250;
OnMenuItemSelected("250ms - AnimateTime");
}
protected void On250Update(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateTime == 250);
}
protected void On1000Selected(object sender, EventArgs e)
{
_topMenu.AnimateTime = 1000;
OnMenuItemSelected("1000ms - AnimateTime");
}
protected void On1000Update(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateTime == 1000);
}
protected void OnBlendSelected(object sender, EventArgs e)
{
_topMenu.AnimateStyle = Animation.Blend;
OnMenuItemSelected("Blend - Animation");
}
protected void OnBlendUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateStyle == Animation.Blend);
}
protected void OnCenterSelected(object sender, EventArgs e)
{
_topMenu.AnimateStyle = Animation.SlideCenter;
OnMenuItemSelected("Center - Animation");
}
protected void OnCenterUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateStyle == Animation.SlideCenter);
}
protected void OnPPSelected(object sender, EventArgs e)
{
_topMenu.AnimateStyle = Animation.SlideHorVerPositive;
OnMenuItemSelected("+Hor +Ver - Animation");
}
protected void OnPPUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateStyle == Animation.SlideHorVerPositive);
}
protected void OnNNSelected(object sender, EventArgs e)
{
_topMenu.AnimateStyle = Animation.SlideHorVerNegative;
OnMenuItemSelected("-Hor -Ver - Animation");
}
protected void OnNNUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateStyle == Animation.SlideHorVerNegative);
}
protected void OnPNSelected(object sender, EventArgs e)
{
_topMenu.AnimateStyle = Animation.SlideHorPosVerNegative;
OnMenuItemSelected("+Hor -Ver - Animation");
}
protected void OnPNUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateStyle == Animation.SlideHorPosVerNegative);
}
protected void OnNPSelected(object sender, EventArgs e)
{
_topMenu.AnimateStyle = Animation.SlideHorNegVerPositive;
OnMenuItemSelected("-Hor +Ver - Animation");
}
protected void OnNPUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateStyle == Animation.SlideHorNegVerPositive);
}
protected void OnSystemSelected(object sender, EventArgs e)
{
_topMenu.AnimateStyle = Animation.System;
OnMenuItemSelected("System - Animation");
}
protected void OnSystemUpdate(object sender, EventArgs e)
{
MenuCommand mc = sender as MenuCommand;
mc.Checked = (_topMenu.AnimateStyle == Animation.System);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
components.Dispose();
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
//
// MDIContainer
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.ControlLight;
this.ClientSize = new System.Drawing.Size(250, 270);
this.Name = "MDIContainer";
this.Text = "SampleMenus";
this.IsMdiContainer = true;
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new MDIContainer());
}
}
class MDIChild : Form
{
protected MDIContainer _mdiContainer;
protected RichTextBox _box;
public MDIChild(MDIContainer mdiContainer)
{
// Remember parent Form
_mdiContainer = mdiContainer;
// Create a RichTextBox to fill entire client area
_box = new RichTextBox();
_box.Text = "Right click inside this window to show a Popup menu.";
_box.Dock = DockStyle.Fill;
_box.BorderStyle = BorderStyle.None;
_box.MouseUp += new MouseEventHandler(OnRichTextMouseUp);
Controls.Add(_box);
}
public void AppendText(string text)
{
_box.Text = _box.Text + "\n" + text;
}
protected void OnRichTextMouseUp(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
RichTextBox box = sender as RichTextBox;
MenuCommand s0 = new MenuCommand("Italy", _mdiContainer.Images, 0);
MenuCommand s1 = new MenuCommand("Spain", _mdiContainer.Images, 1);
MenuCommand s2 = new MenuCommand("Canada", _mdiContainer.Images, 2);
MenuCommand s3 = new MenuCommand("France", _mdiContainer.Images, 3);
MenuCommand s4 = new MenuCommand("Belgium", _mdiContainer.Images, 4);
MenuCommand spain0 = new MenuCommand("Nerja", _mdiContainer.Images, 5);
MenuCommand spain1 = new MenuCommand("Madrid", _mdiContainer.Images, 6);
MenuCommand spain2 = new MenuCommand("Barcelona", _mdiContainer.Images, 0);
MenuCommand canada0 = new MenuCommand("Toronto", _mdiContainer.Images, 5);
MenuCommand canada1 = new MenuCommand("Montreal", _mdiContainer.Images, 6);
MenuCommand canada2 = new MenuCommand("Belleville", _mdiContainer.Images, 0);
MenuCommand england = new MenuCommand("England", _mdiContainer.Images, 2);
MenuCommand england1 = new MenuCommand("London", _mdiContainer.Images, 5);
MenuCommand england2 = new MenuCommand("Birmingham", _mdiContainer.Images, 6);
MenuCommand england3 = new MenuCommand("Nottingham", _mdiContainer.Images, 0);
england.MenuCommands.AddRange(new MenuCommand[]{england1,england2,england3});
s1.MenuCommands.AddRange(new MenuCommand[]{spain0, spain1, spain2});
s2.MenuCommands.AddRange(new MenuCommand[]{canada0, canada1, canada2, england});
// Create the popup menu object
PopupMenu popup = new PopupMenu();
// Define the list of menu commands
popup.MenuCommands.AddRange(new MenuCommand[]{s0, s1, s2, s3, s4});
// Define the properties to get appearance to match MenuControl
popup.Style = _mdiContainer.Style;
popup.Selected += new CommandHandler(OnSelected);
popup.Deselected += new CommandHandler(OnDeselected);
// Show it!
popup.TrackPopup(box.PointToScreen(new Point(e.X, e.Y)));
}
}
protected void OnSelected(MenuCommand mc)
{
_mdiContainer.SetStatusBarText("Selection over " + mc.Description);
}
protected void OnDeselected(MenuCommand mc)
{
_mdiContainer.SetStatusBarText("");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -