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

📄 alarmclockcontroldesigner.cs

📁 中文名:Windows Forms 程序设计 英文名:Windows Forms Programming in c# 作者: Chris Sells 翻译: 荣耀 蒋贤哲 出版社:人民
💻 CS
字号:
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Text;

namespace AlarmClockControlLibrary {
  public class AlarmClockControlDesigner : ScrollableControlDesigner {

    bool showBorder = true;

    DesignerActionListCollection dacl;
    CommandsDesignerActionList cDal;

    public override DesignerActionListCollection ActionLists {
      get {

        if( this.Component == null ) return null;
        
        // Create action list collection
        if( this.dacl == null ) {
          this.dacl = new DesignerActionListCollection();
          //// Add custom action list
          //this.dacl.Add(new AlarmClockControlDesignerActionList(this.Component));

          // Add custom action lists
          this.dacl.Add(new AppearanceDesignerActionList(this.Component));
          this.dacl.Add(new BehaviorDesignerActionList(this.Component));
          this.dacl.Add(new DesignDesignerActionList(this.Component));
        }

        // Hide/Show Commands designer action list as necessary
        if( this.cDal == null ) this.cDal = new CommandsDesignerActionList(this.Component);
        if( this.dacl.Contains(this.cDal) ) this.dacl.Remove(this.cDal);
        if( this.AlarmClockControl.Face != ClockFace.Digital ) {
          this.dacl.Add(this.cDal);
        }

        // Return to the designer action service
        return this.dacl;

        //// Create action list collection
        //DesignerActionListCollection actionLists = new DesignerActionListCollection();

        ////// Add custom action list
        ////actionLists.Add(new AlarmClockControlDesignerActionList(this.Component));

        //actionLists.Add(new AppearanceDesignerActionList(this.Component));
        //actionLists.Add(new BehaviorDesignerActionList(this.Component));
        //actionLists.Add(new DesignDesignerActionList(this.Component));
        //actionLists.Add(new CommandsDesignerActionList(this.Component));
        
        //// Return to the designer action service
        //return actionLists;

      }
    }

    protected override void OnPaintAdornments(PaintEventArgs e) {

      base.OnPaintAdornments(e);

      // Don抰 show border if hidden or does not have an Analog face
      if( (!this.showBorder) || (this.AlarmClockControl.Face == ClockFace.Digital) ) return;

      // Draw border
      Graphics g = e.Graphics;
      using( Pen pen = new Pen(Color.Gray, 1) ) {
        pen.DashStyle = DashStyle.Dash;
        g.DrawRectangle(pen, 0, 0, this.AlarmClockControl.Width - 1, this.AlarmClockControl.Height - 1);
      }
    }

    protected override void PreFilterProperties(IDictionary properties) {
      base.PreFilterProperties(properties);

      // Create design-time-only property entry and add it to the
      // property browser抯 Design category
      properties["ShowBorder"] =
        TypeDescriptor.CreateProperty(
          typeof(AlarmClockControlDesigner),
          "ShowBorder",
          typeof(bool),
          null
        //new Attribute[] {
        //  new CategoryAttribute("Design"),
        //  new DesignOnlyAttribute(true),
        //  new DefaultValueAttribute(true),
        //  new DescriptionAttribute(" Show/Hide a border at design-time.")
        //}
        );
    }

    // Provide implementation of ShowBorder to provide 
    // storage for created ShowBorder property
    [CategoryAttribute("Design")]
    [DesignOnlyAttribute(true)]
    [DefaultValueAttribute(true)]
    [DescriptionAttribute("Show/Hide a border at design-time.")]
    public bool ShowBorder {
      get { return this.showBorder; }
      set {
        // Change property value
        PropertyDescriptor property = TypeDescriptor.GetProperties(typeof(AlarmClockControl))["ShowBorder"];
        this.RaiseComponentChanging(property);
        this.showBorder = value;
        this.RaiseComponentChanged(property, !this.showBorder, this.showBorder);

        // Update clock UI
        this.AlarmClockControl.Invalidate();
      }
    }

    private void ShowBorderClicked(object sender, EventArgs e) {
      // Toggle property value
      ShowBorder = !ShowBorder;
    }

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

⌨️ 快捷键说明

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