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

📄 faceeditorcontrol.cs

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

namespace AlarmClockControlLibrary {
  internal partial class FaceEditorControl : UserControl {

    private ClockFace face = ClockFace.Both;
    private IWindowsFormsEditorService editorService = null;

    public FaceEditorControl() {
      InitializeComponent();
    }
    public FaceEditorControl(IWindowsFormsEditorService editorService) {
      InitializeComponent();
      this.editorService = editorService;
    }

    public ClockFace Face {
      get { return this.face; }
      set { this.face = value; }
    }

    protected override void OnPaint(PaintEventArgs e) {

      // Get currently selected control
      PictureBox selected;
      switch( this.face ) {
        case ClockFace.Analog:
          selected = this.analogPictureBox;
          break;
        case ClockFace.Digital:
          selected = this.digitalPictureBox;
          break;
        default:
          selected = this.bothPictureBox;
          break;
      }

      // Paint the border
      Graphics g = e.Graphics;
      using( Pen pen = new Pen(Color.DarkGray, 1) ) {
        pen.DashStyle = DashStyle.Dash;
        g.DrawLine(pen, new Point(selected.Left - 2, selected.Top - 2), new Point(selected.Left + selected.Width + 1, selected.Top - 2));
        g.DrawLine(pen, new Point(selected.Left + selected.Width + 1, selected.Top - 2), new Point(selected.Left + selected.Width + 1, selected.Top + selected.Height + 1));
        g.DrawLine(pen, new Point(selected.Left + selected.Width + 1, selected.Top + selected.Height + 1), new Point(selected.Left - 2, selected.Top + selected.Height + 1));
        g.DrawLine(pen, new Point(selected.Left - 2, selected.Top + selected.Height + 1), new Point(selected.Left - 2, selected.Top - 2));
      }

      base.OnPaint(e);
    }

    private void analogPictureBox_Click(object sender, EventArgs e) {
      this.face = ClockFace.Analog;

      // Close the UI editor upon value selection
      this.editorService.CloseDropDown();
    }
    private void digitalPictureBox_Click(object sender, EventArgs e) {
      this.face = ClockFace.Digital;

      // Close the UI editor upon value selection
      this.editorService.CloseDropDown();
    }
    private void bothPictureBox_Click(object sender, EventArgs e) {
      this.face = ClockFace.Both;

      // Close the UI editor upon value selection
      this.editorService.CloseDropDown();
    }
  }
}

⌨️ 快捷键说明

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