⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 designdesigneractionlist.cs

📁 中文名:Windows Forms 程序设计 英文名:Windows Forms Programming in c# 作者: Chris Sells 翻译: 荣耀 蒋贤哲 出版社:人民
💻 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 DesignDesignerActionList : DesignerActionList {

    public DesignDesignerActionList(IComponent component) : base(component) { }

    public override DesignerActionItemCollection GetSortedActionItems() {

      if( this.Component == null ) return null;

      // Create list to store designer action items
      DesignerActionItemCollection actionItems = new DesignerActionItemCollection();

      // Fill list of designer action items

      actionItems.Add(new DesignerActionHeaderItem("Design"));

      actionItems.Add(
        new DesignerActionTextItem(
        "Properties that affect the AlarmClockControl at design-time.",
        "Design"));

      // ShowBorder designer action property item
      actionItems.Add(
        new DesignerActionPropertyItem(
          "ShowBorder",
          "Show Border",
          this.GetCategory(this.Designer, "ShowBorder"),
          this.GetDescription(this.Designer, "ShowBorder")));

      // Return list of designer action items
      return actionItems;
    }

    // ShowBorder proxy property
    public bool ShowBorder {
      get { return this.Designer.ShowBorder; }
      set { this.Designer.ShowBorder = value; }
    }

    // Helper method to acquire a AlarmClockControlDesigner reference
    private AlarmClockControlDesigner Designer {
      get {
        IDesignerHost designerHost = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
        if( designerHost == null ) return null;
        return (AlarmClockControlDesigner)designerHost.GetDesigner(this.AlarmClockControl);
      }
    }

    // Helper property to acquire a AlarmClockControl reference
    private AlarmClockControl AlarmClockControl {
      get { return (AlarmClockControl)this.Component; }
    }

    // Helper method that returns the category string from a 
    // CategoryAttribute assigned to a property exposed by the specified  
    // object
    private string GetCategory(object source, string propertyName) {
      PropertyInfo property = source.GetType().GetProperty(propertyName);
      CategoryAttribute attribute = (CategoryAttribute)
        property.GetCustomAttributes(
          typeof(CategoryAttribute), false)[0];
      if( attribute == null ) return null;
      return attribute.Category;
    }

    // Helper method that returns the description string from a 
    // DescriptionAttribute assigned to a property exposed by the 
    // specified object
    private string GetDescription(object source, string propertyName) {
      PropertyInfo property = source.GetType().GetProperty(propertyName);
      DescriptionAttribute attribute = (DescriptionAttribute)
        property.GetCustomAttributes(
          typeof(DescriptionAttribute), false)[0];
      if( attribute == null ) return null;
      return attribute.Description;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -