1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using SmartCoalApplication.SystemLayer;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Forms.VisualStyles;
- namespace SmartCoalApplication.Core
- {
- public sealed class EtchedLine : Control
- {
- private bool selfDrawn = false;
- private Label label;
- public void InitForCurrentVisualStyle()
- {
- switch (UI.VisualStyleClass)
- {
- case VisualStyleClass.Aero:
- this.selfDrawn = true;
- break;
- case VisualStyleClass.Luna:
- case VisualStyleClass.Classic:
- case VisualStyleClass.Other:
- this.selfDrawn = false;
- break;
- default:
- throw new InvalidEnumArgumentException();
- }
- if (this.selfDrawn && (this.label != null && Controls.Contains(this.label)))
- {
- SuspendLayout();
- Controls.Remove(this.label);
- ResumeLayout(false);
- PerformLayout();
- Invalidate(true);
- }
- else if (!this.selfDrawn && (this.label != null || !Controls.Contains(this.label)))
- {
- if (this.label == null)
- {
- this.label = new Label();
- this.label.BorderStyle = BorderStyle.Fixed3D;
- }
- SuspendLayout();
- Controls.Add(this.label);
- ResumeLayout(false);
- PerformLayout();
- Invalidate(true);
- }
- }
- public EtchedLine()
- {
- InitForCurrentVisualStyle();
- DoubleBuffered = true;
- ResizeRedraw = true;
- TabStop = false;
- SetStyle(ControlStyles.Selectable, false);
- }
- public override Size GetPreferredSize(Size proposedSize)
- {
- return new Size(proposedSize.Width, 2);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- if (this.selfDrawn)
- {
- GroupBoxRenderer.DrawGroupBox(e.Graphics, new Rectangle(0, 0, Width, 1), GroupBoxState.Normal);
- }
- base.OnPaint(e);
- }
- protected override void OnLayout(LayoutEventArgs levent)
- {
- if (!this.selfDrawn)
- {
- this.label.Bounds = new System.Drawing.Rectangle(0, 0, Width, Height);
- }
- base.OnLayout(levent);
- }
- }
- }
|