📄 digitalcommandsdesigneractionlist.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
namespace AlarmClockControlLibrary {
public class DigitalCommandsDesignerActionList : DesignerActionList {
public DigitalCommandsDesignerActionList(IComponent component) : base(component) { }
public override DesignerActionItemCollection GetSortedActionItems() {
// Create list to store designer action items
DesignerActionItemCollection actionItems = new DesignerActionItemCollection();
// Fill list of designer action items
actionItems.Add(new DesignerActionHeaderItem("Commands"));
actionItems.Add(
new DesignerActionTextItem(
"Design-Time AlarmClockControl commands.",
"Commands"));
// Dock/Undock designer action method item
actionItems.Add(
new DesignerActionMethodItem(
this,
"ToggleDockStyle",
this.GetDockStyleText(),
"Commands",
"Dock or undock this control in it's parent container."));
// Return list of designer action items
return actionItems;
}
// Toggle AlarmClockControl's Dock property
public void ToggleDockStyle() {
if( this.AlarmClockControl.Dock != DockStyle.Fill ) {
this.SetProperty("Dock", DockStyle.Fill);
}
else {
this.SetProperty("Dock", DockStyle.None);
}
}
// Helper method that returns an appropriate
// display name for the Dock/Undock property,
// based on the AlarmClockControl's current Dock
// property value
private string GetDockStyleText() {
if( this.AlarmClockControl.Dock == DockStyle.Fill ) {
return "Undock in parent container";
}
else {
return "Dock in parent container";
}
}
// Helper method to safely set a component抯 property
private void SetProperty(string propertyName, object value) {
// Get property
PropertyDescriptor property = TypeDescriptor.GetProperties(this.AlarmClockControl)[propertyName];
// Set property value
property.SetValue(this.AlarmClockControl, value);
}
// Helper property to acquire a AlarmClockControl reference
private AlarmClockControl AlarmClockControl {
get { return (AlarmClockControl)this.Component; }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -