📄 panetitle.cs
字号:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace VirtualPhotoOrganizer.Controls
{
/// <summary>
/// Is placed on top of every pane, changes color due to activeness
/// </summary>
internal class PaneTitle : System.Windows.Forms.UserControl
{
// some consts needed for proper drawing
private const int HEIGHT = 20;
private const string FONTNAME = "arial";
private const int FONTSIZE = 9;
private const int OFFSET = 4;
// color and other vars
private bool _Active = false;
private Color ClActiveText = Color.Black;
private Color ClInactiveText = Color.White;
private Color ClActiveLow = Color.FromArgb(255, 165, 78);
private Color ClActiveHigh = Color.FromArgb(255, 225, 155);
private Color ClInactiveLow = Color.FromArgb(3, 55, 145);
private Color ClInactiveHigh = Color.FromArgb(90, 135, 215);
private SolidBrush BrActiveText;
private SolidBrush BrInactiveText;
private LinearGradientBrush BrActive;
private LinearGradientBrush BrInactive;
private StringFormat Format;
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.Container components = null;
public PaneTitle() {
// Dieser Aufruf ist f黵 den Windows Form-Designer erforderlich.
InitializeComponent();
// set the buffer style
this.SetStyle(ControlStyles.DoubleBuffer, true);
// set the height
this.Height = HEIGHT;
// set the string format
Format = new StringFormat();
Format.FormatFlags = StringFormatFlags.NoWrap;
Format.LineAlignment = StringAlignment.Center;
Format.Trimming = StringTrimming.EllipsisCharacter;
// set the font
this.Font = new Font(FONTNAME, FONTSIZE, FontStyle.Bold);
// set the colors
this.ActiveTextColor = ClActiveText;
this.InactiveTextColor = ClInactiveText;
CreateGradientBrushes();
}
/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>
protected override void Dispose(bool disposing) {
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private void DrawText(Graphics g) {
g.FillRectangle(this.BackBrush, this.DisplayRectangle);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
RectangleF bounds = new RectangleF(OFFSET, 0, this.DisplayRectangle.Width - OFFSET, this.DisplayRectangle.Height);
g.DrawString(this.Text, this.Font, this.TextBrush, bounds, Format);
}
protected override void OnPaint(PaintEventArgs e) {
DrawText(e.Graphics);
base.OnPaint(e);
}
protected override void OnSizeChanged(EventArgs e) {
base.OnSizeChanged(e);
CreateGradientBrushes();
}
private void CreateGradientBrushes() {
if (this.Width > 0 && this.Height > 0) {
if (BrActive != null)
BrActive.Dispose();
BrActive = new LinearGradientBrush(this.DisplayRectangle, ClActiveHigh, ClActiveLow, LinearGradientMode.Vertical);
if (BrInactive != null)
BrInactive.Dispose();
BrInactive = new LinearGradientBrush(this.DisplayRectangle, ClInactiveHigh, ClInactiveLow, LinearGradientMode.Vertical);
}
}
#region property-accessors
public override string Text {
get { return base.Text; }
set {
base.Text = value;
Invalidate();
}
}
public bool Active {
get { return _Active; }
set {
_Active = value;
Invalidate();
}
}
private Color ActiveTextColor {
get { return ClActiveText; }
set {
ClActiveText = value;
BrActiveText = new SolidBrush(ClActiveText);
Invalidate();
}
}
private Color InactiveTextColor {
get { return ClInactiveText; }
set {
ClInactiveText = value;
BrInactiveText = new SolidBrush(ClInactiveText);
Invalidate();
}
}
private Color ActiveGradientHighColor {
get { return ClActiveHigh; }
set {
ClActiveHigh = value;
CreateGradientBrushes();
this.Invalidate();
}
}
private Color ActiveGradientLowColor {
get { return ClActiveLow; }
set {
ClActiveLow = value;
CreateGradientBrushes();
this.Invalidate();
}
}
private Color InactiveGradientHighColor {
get { return ClInactiveHigh; }
set {
ClInactiveHigh = value;
CreateGradientBrushes();
this.Invalidate();
}
}
private Color InactiveGradientLowColor {
get { return ClInactiveLow; }
set {
ClInactiveLow = value;
CreateGradientBrushes();
this.Invalidate();
}
}
private SolidBrush TextBrush {
get {
if (_Active == true)
return BrActiveText;
else
return BrInactiveText;
}
}
private LinearGradientBrush BackBrush {
get {
if (_Active == true)
return BrActive;
else
return BrInactive;
}
}
#endregion
#region Vom Komponenten-Designer generierter Code
/// <summary>
/// Erforderliche Methode f黵 die Designerunterst黷zung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor ge鋘dert werden.
/// </summary>
private void InitializeComponent() {
//
// PaneTitle
//
this.Name = "PaneTitle";
this.Size = new System.Drawing.Size(160, 24);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -