g.DrawImage(MinimumButtonImage, minRect);
} else if (MouseButtons != System.Windows.Forms.MouseButtons.Left) { g.DrawImage(MinimumButtonHoverImage, minRect); } else {
g.DrawImage(MinimumButtonPressDownImage, minRect); } } else { g.DrawImage(MinimumButtonImage, minRect); } }
} else if (this.HelpButton) { if (this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.FixedToolWindow && this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.SizableToolWindow) { if (posX != HTHELP) {
g.DrawImage(HelpButtonImage, maxRect);
} else if (MouseButtons != System.Windows.Forms.MouseButtons.Left) {
g.DrawImage(HelpButtonHoverImage, maxRect); } else {
g.DrawImage(HelpButtonPressDownImage, maxRect); } } }
g.Dispose();
ReleaseDC(m.HWnd, dc); }
break;
case WM_NCLBUTTONUP: {
int wp = m.WParam.ToInt32(); switch (wp) { case HTCLOSE:
m.Msg = WM_SYSCOMMAND;
m.WParam = new IntPtr(SC_CLOSE);
break;
case HTMAXBUTTON:
if (this.MaximizeBox) { m.Msg = WM_SYSCOMMAND; if (this.WindowState FormWindowState.Maximized) {
m.WParam = IntPtr(SC_RESTORE);
} else { m.WParam = IntPtr(SC_MAXIMIZE);
} }
break;
case HTMINBUTTON:
if (this.MinimizeBox) { m.Msg = WM_SYSCOMMAND; m.WParam = IntPtr(SC_MINIMIZE);
}
break; case HTHELP:
m.Msg = WM_SYSCOMMAND; m.WParam = IntPtr(SC_CONTEXTHELP);
break; default: break; }
break; }
case WM_NCLBUTTONDOWN: if (this.ControlBox) { bool ret = false; int posX, posY;
int wp = m.WParam.ToInt32(); long lp = m.LParam.ToInt64(); posX = LOBYTE(lp); posY = HIBYTE(lp);
_NonClientSizeInfo ncInfo GetNonClientInfo(m.HWnd);
IntPtr dc = GetWindowDC(m.HWnd);
== new
new
new
new
=
Brush SolidBrush(CaptionBackgroundColor);
backgroundColor = new
Graphics g = Graphics.FromHdc(dc);
int closeBtnPosX = ncInfo.CaptionRect.Left + ncInfo.CaptionRect.Width - ncInfo.BorderSize.Width - ncInfo.CaptionButtonSize.Width;
int maxBtnPosX, minBtnPosX;
int btnPosY = ncInfo.BorderSize.Height + (ncInfo.CaptionHeight - ncInfo.CaptionButtonSize.Height) / 2; maxBtnPosX = closeBtnPosX - ncInfo.CaptionButtonSize.Width;
minBtnPosX = maxBtnPosX - ncInfo.CaptionButtonSize.Width;
Rectangle btnRect = new Rectangle(new Point(closeBtnPosX, btnPosY), ncInfo.CaptionButtonSize);
Rectangle maxRect = new Rectangle(new Point(maxBtnPosX, btnPosY), ncInfo.CaptionButtonSize);
Rectangle minRect = new Rectangle(new Point(minBtnPosX, btnPosY), ncInfo.CaptionButtonSize);
g.FillRectangle(backgroundColor, btnRect); g.FillRectangle(backgroundColor, maxRect); g.FillRectangle(backgroundColor, minRect);
if (wp == HTCLOSE) {
g.DrawImage(CloseButtonPressDownImage, btnRect);
ret = true; } else {
g.DrawImage(CloseButtonImage, btnRect);
}
if (this.MaximizeBox || this.MinimizeBox) { if (this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.SizableToolWindow && this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.FixedToolWindow) { if (this.WindowState == FormWindowState.Maximized) {
if (wp == HTMAXBUTTON && this.MaximizeBox) {
minBtnPosX = maxBtnPosX - ncInfo.CaptionButtonSize.Width;
g.DrawImage(MaximumNormalButtonPressDownImage, maxRect); ret = true; } else {
g.DrawImage(MaximumNormalButtonImage, maxRect); } } else {
if (wp == HTMAXBUTTON && this.MaximizeBox) {
minBtnPosX = maxBtnPosX - ncInfo.CaptionButtonSize.Width;
g.DrawImage(MaximumButtonPressDownImage, maxRect);
ret = true; } else { g.DrawImage(MaximumButtonImage, maxRect); } }
if (wp == HTMINBUTTON && this.MinimizeBox) {
g.DrawImage(MinimumButtonPressDownImage, minRect); ret = true; } else { g.DrawImage(MinimumButtonImage, minRect); } }
} else if (this.HelpButton) { if (this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.FixedToolWindow && this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.SizableToolWindow) { if (wp == HTHELP) {
g.DrawImage(HelpButtonPressDownImage, maxRect); ret = true; } else {
g.DrawImage(HelpButtonImage, maxRect);
} } }
g.Dispose();
ReleaseDC(m.HWnd, dc); if (ret) return; }
break; } }
base.WndProc(ref m); }
#endregion } } 运行效果: