/// <summary> /// /// </summary> /// <param name="G"></param> /// <param name="Rect"></param> /// <param name="BaseColor"></param> /// <param name="BorderColor"></param> /// <param name="InnerBorderColor"></param> /// <param name="Style"></param> /// <param name="RoundWidth"></param> /// <param name="DrawBorder"></param> /// <param name="DrawGlass"></param> /// <param name="Mode"></param> internal static void RenderBackgroundInternal( Graphics G, Rectangle Rect, Color BaseColor, Color BorderColor, Color InnerBorderColor, FormRoundStyle Style, int RoundWidth, bool DrawBorder, bool DrawGlass, LinearGradientMode Mode) { RenderBackgroundInternal( G, Rect, BaseColor, BorderColor, InnerBorderColor, Style, 8, 0.45f, DrawBorder, DrawGlass, Mode, Mode == LinearGradientMode.Vertical ? System.Windows.Forms.Orientation.Horizontal : System.Windows.Forms.Orientation.Vertical); }
/// <summary> /// /// </summary> /// <param name="G"></param> /// <param name="Rect"></param> /// <param name="RStyle"></param> /// <param name="Radius"></param> private void DrawBorder( Graphics G, Rectangle Rect, FormRoundStyle RStyle, int Radius) { Rect.Width -= 1; Rect.Height -= 1; using (GraphicsPath path = FormGraphicsPathHelper.CreatePath( Rect, Radius, RStyle, false)) { using (Pen pen = new Pen(ColorTable.BorderColor)) { G.DrawPath(pen, path); } } Rect.Inflate(-1, -1); using (GraphicsPath path = FormGraphicsPathHelper.CreatePath( Rect, Radius, RStyle, false)) { using (Pen pen = new Pen(ColorTable.InnerBorderColor)) { G.DrawPath(pen, path); } } }
/// <summary> /// /// </summary> /// <param name="G"></param> /// <param name="Rect"></param> /// <param name="State"></param> /// <param name="Active"></param> /// <param name="MinimizeBox"></param> /// <param name="MaximizeBox"></param> private void RenderSkinFormCloseBoxInternal( Graphics G, Rectangle Rect, FormControlBoxState State, bool Active, bool MinimizeBox, bool MaximizeBox) { Color baseColor = ColorTable.ControlBoxActiveColor; if (State == FormControlBoxState.Pressed) { baseColor = ColorTable.ControlCloseBoxPressedColor; } else if (State == FormControlBoxState.Hover) { baseColor = ColorTable.ControlCloseBoxHoverColor; } else { baseColor = Active ? ColorTable.ControlBoxActiveColor : ColorTable.CaptionDeleteActiveColor; } FormRoundStyle roundStyle = MinimizeBox || MaximizeBox ? FormRoundStyle.BottomRight : FormRoundStyle.Bottom; using (FormAntiAliasGraphics antiGraphics = new FormAntiAliasGraphics(G)) { FormRenderHelper.RenderBackgroundInternal( G, Rect, baseColor, baseColor, ColorTable.ControlBoxInnerBorderColor, roundStyle, 6, .38F, false, false, LinearGradientMode.Vertical, System.Windows.Forms.Orientation.Horizontal); using (Pen pen = new Pen(ColorTable.BorderColor)) { G.DrawLine(pen, Rect.X, Rect.Y, Rect.Right, Rect.Y); } using (GraphicsPath path = CreateCloseFlagPath(Rect)) { G.FillPath(Brushes.White, path); using (Pen pen = new Pen(baseColor)) { G.DrawPath(pen, path); } } } }
/// <summary> /// /// </summary> /// <param name="G"></param> /// <param name="Rect"></param> /// <param name="BaseColor"></param> /// <param name="BorderColor"></param> /// <param name="InnerBorderColor"></param> /// <param name="Style"></param> /// <param name="DrawBorder"></param> /// <param name="DrawGlass"></param> /// <param name="Mode"></param> internal static void RenderBackgroundInternal( Graphics G, Rectangle Rect, Color BaseColor, Color BorderColor, Color InnerBorderColor, FormRoundStyle Style, bool DrawBorder, bool DrawGlass, LinearGradientMode Mode) { RenderBackgroundInternal( G, Rect, BaseColor, BorderColor, InnerBorderColor, Style, 8, DrawBorder, DrawGlass, Mode); }
/// <summary> /// /// </summary> /// <param name="G"></param> /// <param name="Rect"></param> /// <param name="BaseColor"></param> /// <param name="BorderColor"></param> /// <param name="InnerBorderColor"></param> /// <param name="Style"></param> /// <param name="RoundWidth"></param> /// <param name="basePosition"></param> /// <param name="DrawBorder"></param> /// <param name="DrawGlass"></param> /// <param name="Mode"></param> internal static void RenderBackgroundInternal( Graphics G, Rectangle Rect, Color BaseColor, Color BorderColor, Color InnerBorderColor, FormRoundStyle Style, int RoundWidth, float basePosition, bool DrawBorder, bool DrawGlass, LinearGradientMode Mode, System.Windows.Forms.Orientation Orientation) { if (DrawBorder) { Rect.Width--; Rect.Height--; } using (LinearGradientBrush brush = new LinearGradientBrush(Rect, Color.Transparent, Color.Transparent, Mode)) { Color[] colors = new Color[4]; colors[0] = GetColor(BaseColor, 0, 35, 24, 9); colors[1] = GetColor(BaseColor, 0, 13, 8, 3); colors[2] = BaseColor; colors[3] = GetColor(BaseColor, 0, 35, 24, 9); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; if (Style != FormRoundStyle.None) { using (GraphicsPath path = FormGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false)) { G.FillPath(brush, path); } if (BaseColor.A > 80) { Rectangle rectTop = Rect; if (Mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(Rect.Width * basePosition); } using (GraphicsPath pathTop = FormGraphicsPathHelper.CreatePath(rectTop, RoundWidth, FormRoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { G.FillPath(brushAlpha, pathTop); } } } if (DrawGlass) { RectangleF glassRect = Rect; if (Mode == LinearGradientMode.Vertical) { glassRect.Y = Rect.Y + Rect.Height * basePosition; glassRect.Height = (Rect.Height - Rect.Height * basePosition) * 2; } else { glassRect.X = Rect.X + Rect.Width * basePosition; glassRect.Width = (Rect.Width - Rect.Width * basePosition) * 2; } FormControlPaintEx.DrawGlass(G, glassRect, 170, 0, Orientation); } if (DrawBorder) { using (GraphicsPath path = FormGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false)) { using (Pen pen = new Pen(BorderColor)) { G.DrawPath(pen, path); } } Rect.Inflate(-1, -1); using (GraphicsPath path = FormGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false)) { using (Pen pen = new Pen(InnerBorderColor)) { G.DrawPath(pen, path); } } } } else { G.FillRectangle(brush, Rect); if (BaseColor.A > 80) { Rectangle rectTop = Rect; if (Mode == LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(Rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { G.FillRectangle(brushAlpha, rectTop); } } if (DrawGlass) { RectangleF glassRect = Rect; if (Mode == LinearGradientMode.Vertical) { glassRect.Y = Rect.Y + Rect.Height * basePosition; glassRect.Height = (Rect.Height - Rect.Height * basePosition) * 2; } else { glassRect.X = Rect.X + Rect.Width * basePosition; glassRect.Width = (Rect.Width - Rect.Width * basePosition) * 2; } FormControlPaintEx.DrawGlass(G, glassRect, 200, 0, Orientation); } if (DrawBorder) { using (Pen pen = new Pen(BorderColor)) { G.DrawRectangle(pen, Rect); } Rect.Inflate(-1, -1); using (Pen pen = new Pen(InnerBorderColor)) { G.DrawRectangle(pen, Rect); } } } } }
/// <summary> /// 建立帶有圓角樣式的路徑。 /// </summary> /// <param name="Rect">用來建立路徑的矩形。</param> /// <param name="Radius">圓角的大小。</param> /// <param name="Style">圓角的樣式。</param> /// <param name="CorRection">是否把矩形長寬減 1,以便畫出邊框。</param> /// <returns>建立的路徑。</returns> public static GraphicsPath CreatePath( Rectangle Rect, int Radius, FormRoundStyle Style, bool CorRection) { GraphicsPath path = new GraphicsPath(); int RadiusCorRection = CorRection ? 1 : 0; switch (Style) { case FormRoundStyle.None: path.AddRectangle(Rect); break; case FormRoundStyle.All: path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90); path.AddArc( Rect.Right - Radius - RadiusCorRection, Rect.Y, Radius, Radius, 270, 90); path.AddArc( Rect.Right - Radius - RadiusCorRection, Rect.Bottom - Radius - RadiusCorRection, Radius, Radius, 0, 90); path.AddArc( Rect.X, Rect.Bottom - Radius - RadiusCorRection, Radius, Radius, 90, 90); break; case FormRoundStyle.Left: path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90); path.AddLine( Rect.Right - RadiusCorRection, Rect.Y, Rect.Right - RadiusCorRection, Rect.Bottom - RadiusCorRection); path.AddArc( Rect.X, Rect.Bottom - Radius - RadiusCorRection, Radius, Radius, 90, 90); break; case FormRoundStyle.Right: path.AddArc( Rect.Right - Radius - RadiusCorRection, Rect.Y, Radius, Radius, 270, 90); path.AddArc( Rect.Right - Radius - RadiusCorRection, Rect.Bottom - Radius - RadiusCorRection, Radius, Radius, 0, 90); path.AddLine(Rect.X, Rect.Bottom - RadiusCorRection, Rect.X, Rect.Y); break; case FormRoundStyle.Top: path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90); path.AddArc( Rect.Right - Radius - RadiusCorRection, Rect.Y, Radius, Radius, 270, 90); path.AddLine( Rect.Right - RadiusCorRection, Rect.Bottom - RadiusCorRection, Rect.X, Rect.Bottom - RadiusCorRection); break; case FormRoundStyle.Bottom: path.AddArc( Rect.Right - Radius - RadiusCorRection, Rect.Bottom - Radius - RadiusCorRection, Radius, Radius, 0, 90); path.AddArc( Rect.X, Rect.Bottom - Radius - RadiusCorRection, Radius, Radius, 90, 90); path.AddLine(Rect.X, Rect.Y, Rect.Right - RadiusCorRection, Rect.Y); break; case FormRoundStyle.BottomLeft: path.AddArc( Rect.X, Rect.Bottom - Radius - RadiusCorRection, Radius, Radius, 90, 90); path.AddLine(Rect.X, Rect.Y, Rect.Right - RadiusCorRection, Rect.Y); path.AddLine( Rect.Right - RadiusCorRection, Rect.Y, Rect.Right - RadiusCorRection, Rect.Bottom - RadiusCorRection); break; case FormRoundStyle.BottomRight: path.AddArc( Rect.Right - Radius - RadiusCorRection, Rect.Bottom - Radius - RadiusCorRection, Radius, Radius, 0, 90); path.AddLine(Rect.X, Rect.Bottom - RadiusCorRection, Rect.X, Rect.Y); path.AddLine(Rect.X, Rect.Y, Rect.Right - RadiusCorRection, Rect.Y); break; } path.CloseFigure(); return(path); }