📄 dockpanecaptionvs2005.cs
字号:
/// <include file='CodeDoc/DockPaneCaptionVS2003.xml' path='//CodeDoc/Class[@name="DockPaneCaptionVS2003"]/Property[@name="ActiveBackColor"]/*'/>
protected virtual Brush ActiveBackBrush
{
get {
Fireball.Docking.Drawing.ColorHLS hls = new Fireball.Docking.Drawing.ColorHLS(SystemColors.InactiveCaption);
hls.Lighten(0.02f);
Rectangle rect = this.ClientRectangle;
if(rect == Rectangle.Empty)
rect = new Rectangle(0,0,1,1);
LinearGradientBrush lnbr = new LinearGradientBrush(rect,
hls.Color,SystemColors.ActiveCaption, LinearGradientMode.Vertical);
return lnbr;
}
}
/// <include file='CodeDoc/DockPaneCaptionVS2003.xml' path='//CodeDoc/Class[@name="DockPaneCaptionVS2003"]/Property[@name="InactiveBackColor"]/*'/>
protected virtual Brush InactiveBackBrush
{
get { return SystemBrushes.ControlDark; }
}
/// <include file='CodeDoc/DockPaneCaptionVS2003.xml' path='//CodeDoc/Class[@name="DockPaneCaptionVS2003"]/Property[@name="ActiveTextColor"]/*'/>
protected virtual Color ActiveTextColor
{
get { return SystemColors.ActiveCaptionText; }
}
/// <include file='CodeDoc/DockPaneCaptionVS2003.xml' path='//CodeDoc/Class[@name="DockPaneCaptionVS2003"]/Property[@name="InactiveTextColor"]/*'/>
protected virtual Color InactiveTextColor
{
get { return SystemColors.ControlText; }
}
/// <include file='CodeDoc/DockPaneCaptionVS2003.xml' path='//CodeDoc/Class[@name="DockPaneCaptionVS2003"]/Property[@name="InactiveBorderColor"]/*'/>
protected virtual Color InactiveBorderColor
{
get { return SystemColors.GrayText; }
}
/// <include file='CodeDoc/DockPaneCaptionVS2003.xml' path='//CodeDoc/Class[@name="DockPaneCaptionVS2003"]/Property[@name="ActiveButtonBorderColor"]/*'/>
protected virtual Color ActiveButtonBorderColor
{
get { return ActiveTextColor; }
}
/// <include file='CodeDoc/DockPaneCaptionVS2003.xml' path='//CodeDoc/Class[@name="DockPaneCaptionVS2003"]/Property[@name="InactiveButtonBorderColor"]/*'/>
protected virtual Color InactiveButtonBorderColor
{
get { return Color.Empty; }
}
private static StringFormat _textStringFormat = null;
/// <include file='CodeDoc/DockPaneCaptionVS2003.xml' path='//CodeDoc/Class[@name="DockPaneCaptionVS2003"]/Property[@name="TextStringFormat"]/*'/>
protected virtual StringFormat TextStringFormat
{
get
{
if (_textStringFormat == null)
{
_textStringFormat = new StringFormat();
_textStringFormat.Trimming = StringTrimming.EllipsisCharacter;
_textStringFormat.LineAlignment = StringAlignment.Center;
_textStringFormat.FormatFlags = StringFormatFlags.NoWrap;
}
return _textStringFormat;
}
}
#endregion
/// <exclude/>
protected internal override int MeasureHeight()
{
int height = Font.Height + TextGapTop + TextGapBottom;
if (height < ImageCloseEnabled.Height + ButtonGapTop + ButtonGapBottom)
height = ImageCloseEnabled.Height + ButtonGapTop + ButtonGapBottom;
return height;
}
/// <exclude/>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
//e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
DrawCaption(e.Graphics);
}
private void DrawCaption(Graphics g)
{
//BackColor = DockPane.IsActivated ? ActiveBackColor : InactiveBackColor;
if (DockPane.IsActivated)
g.FillRectangle(this.ActiveBackBrush, this.ClientRectangle);
else
g.FillRectangle(this.InactiveBackBrush, this.ClientRectangle);
Rectangle rectCaption = ClientRectangle;
if (!DockPane.IsActivated)
{
using (Pen pen = new Pen(InactiveBorderColor))
{
g.DrawLine(pen, rectCaption.X + 1, rectCaption.Y, rectCaption.X + rectCaption.Width - 2, rectCaption.Y);
g.DrawLine(pen, rectCaption.X + 1, rectCaption.Y + rectCaption.Height - 1, rectCaption.X + rectCaption.Width - 2, rectCaption.Y + rectCaption.Height - 1);
g.DrawLine(pen, rectCaption.X, rectCaption.Y + 1, rectCaption.X, rectCaption.Y + rectCaption.Height - 2);
g.DrawLine(pen, rectCaption.X + rectCaption.Width - 1, rectCaption.Y + 1, rectCaption.X + rectCaption.Width - 1, rectCaption.Y + rectCaption.Height - 2);
}
}
m_buttonClose.ForeColor = m_buttonAutoHide.ForeColor = (DockPane.IsActivated ? ActiveTextColor : InactiveTextColor);
m_buttonClose.BorderColor = m_buttonAutoHide.BorderColor = (DockPane.IsActivated ? ActiveButtonBorderColor : InactiveButtonBorderColor);
Rectangle rectCaptionText = rectCaption;
rectCaptionText.X += TextGapLeft;
if (ShouldShowCloseButton && ShouldShowAutoHideButton)
rectCaptionText.Width = rectCaption.Width - ButtonGapRight
- ButtonGapLeft - TextGapLeft - TextGapRight -
(m_buttonAutoHide.Width + ButtonGapBetween + m_buttonClose.Width);
else if (ShouldShowCloseButton || ShouldShowAutoHideButton)
rectCaptionText.Width = rectCaption.Width - ButtonGapRight
- ButtonGapLeft - TextGapLeft - TextGapRight - m_buttonClose.Width;
else
rectCaptionText.Width = rectCaption.Width - TextGapLeft - TextGapRight;
rectCaptionText.Y += TextGapTop;
rectCaptionText.Height -= TextGapTop + TextGapBottom;
using (Brush brush = new SolidBrush(DockPane.IsActivated ? ActiveTextColor : InactiveTextColor))
{
g.DrawString(DockPane.CaptionText, Font, brush, rectCaptionText, TextStringFormat);
}
}
/// <exclude/>
protected override void OnLayout(LayoutEventArgs levent)
{
SetButtonsPosition();
base.OnLayout (levent);
}
/// <exclude/>
protected override void OnRefreshChanges()
{
SetButtons();
Invalidate();
}
private bool ShouldShowCloseButton
{
get { return (DockPane.ActiveContent != null)? DockPane.ActiveContent.DockHandler.CloseButton : false; }
}
private bool ShouldShowAutoHideButton
{
get { return !DockPane.IsFloat; }
}
private void SetButtons()
{
m_buttonClose.Visible = ShouldShowCloseButton;
m_buttonAutoHide.Visible = ShouldShowAutoHideButton;
m_buttonAutoHide.ImageEnabled = DockPane.IsAutoHide ? ImageAutoHideYes : ImageAutoHideNo;
SetButtonsPosition();
}
private void SetButtonsPosition()
{
// set the size and location for close and auto-hide buttons
Rectangle rectCaption = ClientRectangle;
int buttonWidth = ImageCloseEnabled.Width;
int buttonHeight = ImageCloseEnabled.Height;
int height = rectCaption.Height - ButtonGapTop - ButtonGapBottom;
if (buttonHeight < height)
{
buttonWidth = buttonWidth * (height / buttonHeight);
buttonHeight = height;
}
m_buttonClose.SuspendLayout();
m_buttonAutoHide.SuspendLayout();
Size buttonSize = new Size(buttonWidth, buttonHeight);
m_buttonClose.Size = m_buttonAutoHide.Size = buttonSize;
int x = rectCaption.X + rectCaption.Width - 1 - ButtonGapRight - m_buttonClose.Width;
int y = rectCaption.Y + ButtonGapTop;
Point point = m_buttonClose.Location = new Point(x, y);
if (ShouldShowCloseButton)
point.Offset(-(m_buttonAutoHide.Width + ButtonGapBetween), 0);
m_buttonAutoHide.Location = point;
m_buttonClose.ResumeLayout();
m_buttonAutoHide.ResumeLayout();
}
private void Close_Click(object sender, EventArgs e)
{
DockPane.CloseActiveContent();
}
private void AutoHide_Click(object sender, EventArgs e)
{
DockPane.DockState = DockHelper.ToggleAutoHideState(DockPane.DockState);
if (!DockPane.IsAutoHide)
DockPane.Activate();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -