📄 dockpanestripvs2005.cs
字号:
int w = (int)(size.Width + size.Height / 2) + (int)font.Size;
w = Math.Min(w, this.DocumentTabMaxWidth + this.DocumentTextExtraWidth * 2);
if (w > 0)
tab.TabWidth = w;
int x = tab.TabX;
if (index > 0)
{
x += ((int)(font.Size / 1.5f) * index);
//x += (int)font.Size * index;
}
// x -= m_offsetX;
return new Rectangle(x, rectTabStrip.Y + DocumentTabGapTop,w /*tab.TabWidth*/, rectTabStrip.Height - DocumentTabGapTop);
}
private void DrawTab(Graphics g, IDockableWindow content, Rectangle rect)
{
OnBeginDrawTab(content.DockHandler.DockPaneTab);
if (Appearance == DockPane.AppearanceStyle.ToolWindow)
DrawTab_ToolWindow(g, content, rect);
else
DrawTab_Document(g, content, rect);
OnEndDrawTab(content.DockHandler.DockPaneTab);
}
private void DrawTab_ToolWindow(Graphics g, IDockableWindow content, Rectangle rect)
{
GraphicsPath gp = new GraphicsPath();
gp.AddLine(rect.X, rect.Top - 1, rect.Right - 1, rect.Top - 1);
gp.AddLine(rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 3);
gp.AddLine(rect.Right - 3, rect.Bottom - 1, rect.X + 2, rect.Bottom - 1);
gp.AddLine(rect.X, rect.Bottom - 3, rect.X, rect.Top);
gp.CloseAllFigures();
Rectangle rectIcon = new Rectangle(
rect.X + ToolWindowImageGapLeft,
rect.Y + rect.Height - 1 - ToolWindowImageGapBottom - ToolWindowImageHeight,
ToolWindowImageWidth, ToolWindowImageHeight);
Rectangle rectText = rectIcon;
rectText.X += rectIcon.Width + ToolWindowImageGapRight;
rectText.Width = rect.Width - rectIcon.Width - ToolWindowImageGapLeft -
ToolWindowImageGapRight - ToolWindowTextGapRight;
if (DockPane.ActiveContent == content)
{
LinearGradientBrush lnbr = new LinearGradientBrush(rect, this.ActiveBackColor2,
this.ActiveBackColor1, LinearGradientMode.Vertical);
g.FillPath(lnbr, gp);
g.DrawPath(OutlineOuterPen, gp);
/* g.FillRectangle(lnbr, rect);
g.DrawLine(OutlineOuterPen,
rect.X, rect.Y, rect.X, rect.Y + rect.Height - 1);
g.DrawLine(OutlineInnerPen,
rect.X, rect.Y + rect.Height - 1, rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
g.DrawLine(OutlineInnerPen,
rect.X + rect.Width - 1, rect.Y, rect.X + rect.Width - 1, rect.Y + rect.Height - 1);*/
g.DrawString(content.DockHandler.TabText, Font, ActiveTextBrush, rectText, ToolWindowTextStringFormat);
}
else
{
if (Tabs.IndexOf(DockPane.ActiveContent) != Tabs.IndexOf(content) + 1)
g.DrawLine(TabSeperatorPen,
rect.X + rect.Width - 1,
rect.Y + ToolWindowTabSeperatorGapTop,
rect.X + rect.Width - 1,
rect.Y + rect.Height - 1 - ToolWindowTabSeperatorGapBottom);
g.DrawString(content.DockHandler.TabText, Font, InactiveTextBrush, rectText, ToolWindowTextStringFormat);
}
if (rect.Contains(rectIcon))
g.DrawIcon(content.DockHandler.Icon, rectIcon);
}
private void DrawTab_Document(Graphics g, IDockableWindow content, Rectangle rect)
{
SmoothingMode mode = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.AntiAlias;
GraphicsPath gp = new GraphicsPath();
gp.AddLine(rect.X, rect.Bottom, rect.X + (rect.Height / 2), rect.Top + 2);
gp.AddLine(rect.X + (rect.Height / 2) + 4, rect.Top, rect.Right - 2, rect.Top);
gp.AddLine(rect.Right, rect.Top + 2, rect.Right, rect.Bottom);
Rectangle rectText = rect;
if (DockPane.DockPanel.ShowDocumentIcon)
{
rectText.X += DocumentTextExtraWidth / 2 + DocumentIconWidth + DocumentIconGapLeft;
rectText.Width -= DocumentTextExtraWidth + DocumentIconWidth + DocumentIconGapLeft;
}
else
{
rectText.X += DocumentTextExtraWidth / 2;
rectText.Width -= DocumentTextExtraWidth;
}
rectText.X += (rect.Height/2 );
rectText.Width -= (rect.Height /2);
if (DockPane.ActiveContent == content)
{
/*g.FillRectangle(ActiveBackBrush, rect);
g.DrawLine(OutlineOuterPen, rect.X, rect.Y, rect.X, rect.Y + rect.Height);
g.DrawLine(OutlineOuterPen, rect.X, rect.Y, rect.X + rect.Width - 1, rect.Y);
g.DrawLine(OutlineInnerPen,
rect.X + rect.Width - 1, rect.Y,
rect.X + rect.Width - 1, rect.Y + rect.Height - 1);*/
LinearGradientBrush lnbr = new LinearGradientBrush(rect,this.ActiveBackColor2,
this.ActiveBackColor1, LinearGradientMode.Vertical );
g.FillPath(lnbr, gp);
g.DrawPath(OutlineOuterPen, gp);
if (DockPane.DockPanel.ShowDocumentIcon)
{
Icon icon = (content as Form).Icon;
Rectangle rectIcon = new Rectangle(
rect.X + DocumentIconGapLeft,
rect.Y + (rect.Height - DocumentIconHeight) / 2,
DocumentIconWidth, DocumentIconHeight);
g.DrawIcon((content as Form).Icon, rectIcon);
}
if (DockPane.IsActiveDocumentPane)
{
using (Font boldFont = new Font(this.Font, FontStyle.Bold))
{
g.DrawString(content.DockHandler.TabText, boldFont, ActiveTextBrush, rectText, DocumentTextStringFormat);
}
}
else
g.DrawString(content.DockHandler.TabText, Font, InactiveTextBrush, rectText, DocumentTextStringFormat);
g.DrawLine(this.OutlineOuterPen, 0, rect.Bottom - 1, rect.Left, rect.Bottom - 1);
}
else
{
LinearGradientBrush lnbr = new LinearGradientBrush(rect, this.ActiveBackColor1,
this.ActiveBackColor2, LinearGradientMode.Vertical);
g.FillPath(lnbr, gp);
g.DrawPath(OutlineOuterPen, gp);
//if (Tabs.IndexOf(DockPane.ActiveContent) != Tabs.IndexOf(content) + 1)
// g.DrawLine(TabSeperatorPen,
// rect.X + rect.Width - 1, rect.Y,
// rect.X + rect.Width - 1, rect.Y + rect.Height - 1 - DocumentTabGapTop);
if (DockPane.DockPanel.ShowDocumentIcon)
{
Icon icon = (content as Form).Icon;
Rectangle rectIcon = new Rectangle(
rect.X + DocumentIconGapLeft,
rect.Y + (rect.Height - DocumentIconHeight) / 2,
DocumentIconWidth, DocumentIconHeight);
g.DrawIcon((content as Form).Icon, rectIcon);
}
g.DrawString(content.DockHandler.TabText, Font, InactiveTextBrush, rectText, DocumentTextStringFormat);
g.DrawLine(this.OutlineOuterPen, rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1);
}
g.SmoothingMode = mode;
}
private Rectangle TabsRectangle
{
get
{
if (Appearance == DockPane.AppearanceStyle.ToolWindow)
return ClientRectangle;
Rectangle rectWindow = ClientRectangle;
int x = rectWindow.X;
int y = rectWindow.Y;
int width = rectWindow.Width;
int height = rectWindow.Height;
x += DocumentTabGapLeft;
width -= DocumentTabGapLeft +
DocumentTabGapRight +
DocumentButtonGapRight +
m_buttonClose.Width +
m_buttonScrollRight.Width +
m_buttonScrollLeft.Width +
2 * DocumentButtonGapBetween;
return new Rectangle(x, y, width, height);
}
}
private void ScrollLeft_Click(object sender, EventArgs e)
{
Rectangle rectTabStrip = TabsRectangle;
int index;
for (index=0; index<Tabs.Count; index++)
if (GetTabRectangle(index).IntersectsWith(rectTabStrip))
break;
Rectangle rectTab = GetTabRectangle(index);
if (rectTab.Left < rectTabStrip.Left)
OffsetX += rectTabStrip.Left - rectTab.Left;
else if (index == 0)
OffsetX = 0;
else
OffsetX += rectTabStrip.Left - GetTabRectangle(index - 1).Left;
OnRefreshChanges();
}
private void ScrollRight_Click(object sender, EventArgs e)
{
Rectangle rectTabStrip = TabsRectangle;
int index;
int count = Tabs.Count;
for (index=0; index<count; index++)
if (GetTabRectangle(index).IntersectsWith(rectTabStrip))
break;
if (index + 1 < count)
{
OffsetX -= GetTabRectangle(index + 1).Left - rectTabStrip.Left;
CalculateTabs();
}
Rectangle rectLastTab = GetTabRectangle(count - 1);
if (rectLastTab.Right < rectTabStrip.Right)
OffsetX += rectTabStrip.Right - rectLastTab.Right;
OnRefreshChanges();
}
private void SetInertButtons()
{
// Set the visibility of the inert buttons
m_buttonScrollLeft.Visible = m_buttonScrollRight.Visible = m_buttonClose.Visible = (DockPane.DockState == DockState.Document);
m_buttonClose.ForeColor = m_buttonScrollRight.ForeColor = m_buttonScrollLeft.ForeColor = SystemColors.ControlDarkDark;
m_buttonClose.BorderColor = m_buttonScrollRight.BorderColor = m_buttonScrollLeft.BorderColor = SystemColors.ControlDarkDark;
// Enable/disable scroll buttons
int count = Tabs.Count;
Rectangle rectTabOnly = TabsRectangle;
Rectangle rectTab = (count == 0) ? Rectangle.Empty : GetTabRectangle(count - 1);
m_buttonScrollLeft.Enabled = (OffsetX < 0);
m_buttonScrollRight.Enabled = rectTab.Right > rectTabOnly.Right;
// show/hide close button
if (Appearance == DockPane.AppearanceStyle.ToolWindow)
m_buttonClose.Visible = false;
else
{
bool showCloseButton = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButton;
if (m_buttonClose.Visible != showCloseButton)
{
m_buttonClose.Visible = showCloseButton;
PerformLayout();
}
}
}
/// <exclude/>
protected override void OnLayout(LayoutEventArgs levent)
{
Rectangle rectTabStrip = ClientRectangle;
// Set position and size of the buttons
int buttonWidth = ImageCloseEnabled.Width;
int buttonHeight = ImageCloseEnabled.Height;
int height = rectTabStrip.Height - DocumentButtonGapTop - DocumentButtonGapBottom;
if (buttonHeight < height)
{
buttonWidth = buttonWidth * (height / buttonHeight);
buttonHeight = height;
}
Size buttonSize = new Size(buttonWidth, buttonHeight);
m_buttonClose.Size = m_buttonScrollLeft.Size = m_buttonScrollRight.Size = buttonSize;
int x = rectTabStrip.X + rectTabStrip.Width - DocumentTabGapLeft
- DocumentButtonGapRight - buttonWidth;
int y = rectTabStrip.Y + DocumentButtonGapTop;
m_buttonClose.Location = new Point(x, y);
Point point = m_buttonClose.Location;
bool showCloseButton = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButton;
if (showCloseButton)
point.Offset(-(DocumentButtonGapBetween + buttonWidth), 0);
m_buttonScrollRight.Location = point;
point.Offset(-(DocumentButtonGapBetween + buttonWidth), 0);
m_buttonScrollLeft.Location = point;
OnRefreshChanges();
base.OnLayout (levent);
}
private void Close_Click(object sender, EventArgs e)
{
DockPane.CloseActiveContent();
}
/// <exclude/>
protected internal override int GetHitTest(Point ptMouse)
{
Rectangle rectTabStrip = TabsRectangle;
for (int i=0; i<Tabs.Count; i++)
{
Rectangle rectTab = GetTabRectangle(i);
rectTab.Intersect(rectTabStrip);
if (rectTab.Contains(ptMouse))
return i;
}
return -1;
}
/// <exclude/>
protected override void OnMouseMove(MouseEventArgs e)
{
int index = GetHitTest(PointToClient(Control.MousePosition));
string toolTip = string.Empty;
base.OnMouseMove(e);
if (index != -1)
{
Rectangle rectTab = GetTabRectangle(index);
if (Tabs[index].Content.DockHandler.ToolTipText != null)
toolTip = Tabs[index].Content.DockHandler.ToolTipText;
else if (rectTab.Width < GetTabOriginalWidth(index))
toolTip = Tabs[index].Content.DockHandler.TabText;
}
if (m_toolTip.GetToolTip(this) != toolTip)
{
m_toolTip.Active = false;
m_toolTip.SetToolTip(this, toolTip);
m_toolTip.Active = true;
}
}
/// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnBeginDrawTabStrip()"]/*'/>
protected virtual void OnBeginDrawTabStrip()
{
}
/// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnEndDrawTabStrip()"]/*'/>
protected virtual void OnEndDrawTabStrip()
{
}
/// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnBeginDrawTab(DockPaneTab)"]/*'/>
protected virtual void OnBeginDrawTab(DockPaneTab tab)
{
}
/// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnEndDrawTab(DockPaneTab)"]/*'/>
protected virtual void OnEndDrawTab(DockPaneTab tab)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -