Exemplo n.º 1
0
        public static void CreateRegion(IntPtr hWnd, int radius, RoundStyle roundStyle, bool redraw)
        {
            var lpRect = new RECT();

            NativeMethods.GetWindowRect(hWnd, ref lpRect);
            var rect = new Rectangle(Point.Empty, lpRect.Size);

            if (roundStyle != RoundStyle.None)
            {
                using (var path = DrawHelper.CreateRoundPath(rect, radius, roundStyle, true)) //
                {
                    using (var region = new Region(path))
                    {
                        path.Widen(Pens.White);
                        region.Union(path);
                        var windowDC = NativeMethods.GetWindowDC(hWnd);
                        try
                        {
                            using (var graphics = Graphics.FromHdc(windowDC))
                            {
                                NativeMethods.SetWindowRgn(hWnd, region.GetHrgn(graphics), redraw);
                            }
                        }
                        finally
                        {
                            NativeMethods.ReleaseDC(hWnd, windowDC);
                        }
                    }
                    return;
                }
            }
            var hRgn = NativeMethods.CreateRectRgn(0, 0, rect.Width, rect.Height);

            NativeMethods.SetWindowRgn(hWnd, hRgn, redraw);
        }
Exemplo n.º 2
0
 internal static void DrawGradientRoundRect(Graphics g, Rectangle rect, Color begin, Color end, Color border,
                                            Color innerBorder, Blend blend, LinearGradientMode mode, int radios, RoundStyle roundStyle, bool drawBorder,
                                            bool drawInnderBorder)
 {
     using (var path = DrawHelper.CreateRoundPath(rect, radios, roundStyle, true)) //
     {
         using (var brush = new LinearGradientBrush(rect, begin, end, mode))
         {
             brush.Blend = blend;
             g.FillPath(brush, path);
         }
         if (drawBorder)
         {
             using (var pen = new Pen(border))
             {
                 g.DrawPath(pen, path);
             }
         }
     }
     if (drawInnderBorder)
     {
         rect.Inflate(-1, -1);
         using (var path2 = DrawHelper.CreateRoundPath(rect, radios, roundStyle, true)) //
         {
             using (var pen2 = new Pen(innerBorder))
             {
                 g.DrawPath(pen2, path2);
             }
         }
     }
 }
Exemplo n.º 3
0
 protected override void OnPaint(PaintEventArgs e)
 {
     //if (BorderStyle != BorderStyle.None)
     //{
     e.Graphics.DrawPath(new Pen(Color.Red), DrawHelper.CreateRoundPath(Width, Height, 3));
     //}
     //base.OnPaint(e);
 }
Exemplo n.º 4
0
        public override Region CreateRegion(CForm form)
        {
            var rect = new Rectangle(Point.Empty, form.Size);

            using (var path = DrawHelper.CreateRoundPath(rect, form.Radius, form.RoundStyle, false)) //
            {
                return(new Region(path));
            }
        }
Exemplo n.º 5
0
 public static void CreateRegion(Control control, Rectangle bounds, int radius)
 {
     using (var path = DrawHelper.CreateRoundPath(bounds.Width - 1, bounds.Height - 1, radius)) //
     {
         var region = new Region(path);
         path.Widen(Pens.White);
         region.Union(path);
         control.Region = region;
     }
 }
Exemplo n.º 6
0
 public static void CreateRegion(Control control, Rectangle bounds, int radius, RoundStyle roundStyle)
 {
     using (var path = DrawHelper.CreateRoundPath(bounds, radius, roundStyle, true)) //
     {
         var region = new Region(path);
         path.Widen(Pens.White);
         region.Union(path);
         control.Region = region;
     }
 }
Exemplo n.º 7
0
        public override Region CreateRegion(CForm form)
        {
            var rect = new Rectangle(Point.Empty, form.Size);

            using (var path = DrawHelper.CreateRoundPath(rect, form.Radius, form.RoundStyle, false)) //
            {
                return(new Region(path));
            }

            //using (var path = DrawHelper.CreateRoundPath(rect.Width-5, rect.Height-5, form.Radius)) //
            //{
            //    return new Region(path);
            //}
        }
Exemplo n.º 8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var dc = e.Graphics;

            dc.SmoothingMode     = SmoothingMode.AntiAlias;
            dc.TextRenderingHint = TextRenderingHint.AntiAlias;
            //背景
            using (var sb = new SolidBrush(bgColor))
            {
                dc.FillRectangle(sb, 0, 0, base.Width, base.Height);
            }

            var y = showBorder ? 1 : 0;

            if (list != null && list.Count >= 1)
            {
                base.Height = (this.itemHeight * this.list.Count) + y * 2; //这里加2 就是为了防止边框盖住子项
                for (var i = 0; i < this.list.Count; i++)
                {
                    this.list[i].Bounds = new Rectangle(2, y, base.Width - 4, this.itemHeight);
                    if (this.list[i].Move)
                    {
                        fontHoverColor = fontHoverColor == Color.Empty ? Color.FromArgb(100, bgColor) : fontHoverColor;
                        using (var sb1 = new SolidBrush(fontHoverColor))
                        {
                            dc.FillRectangle(sb1, this.list[i].Bounds);
                        }
                    }
                    TextRenderer.DrawText(e.Graphics, this.list[i].Text, Font, this.list[i].Bounds, ForeColor,
                                          TextFormatFlags.VerticalCenter);

                    //  TextRenderer.DrawText(dc, this.list[i].Text, this.Font, new Point(5, y), this.FontColor,TextFormatFlags.VerticalCenter);
                    y += this.itemHeight;
                }
            }
            //边框
            if (showBorder)
            {
                using (var path = DrawHelper.CreateRoundPath(ClientRectangle, mRadius))
                {
                    using (var pen = new Pen(Color.FromArgb(100, bgColor)))
                    {
                        dc.DrawPath(pen, path);
                    }
                }
            }
        }
Exemplo n.º 9
0
 private void DrawBorder(Graphics g, Rectangle rect, RoundStyle roundStyle, int radius, CForm frm)
 {
     g.SmoothingMode = SmoothingMode.HighQuality;
     rect.Width--;
     rect.Height--;
     using (var path = DrawHelper.CreateRoundPath(rect, radius, roundStyle, false)) //
     {
         using (var pen = new Pen(ColorTable.Border))
         {
             g.DrawPath(pen, path);
         }
     }
     rect.Inflate(-1, -1);
     using (var path2 = DrawHelper.CreateRoundPath(rect, radius, roundStyle, false)) //
     {
         using (var pen2 = new Pen(ColorTable.InnerBorder))
         {
             g.DrawPath(pen2, path2);
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 ///     画边框与背景
 /// </summary>
 internal void RenderBackGroundInternal(
     Graphics g,
     Rectangle rect,
     RoundStyle style,
     int roundWidth
     )
 {
     if (ControlStates != ControlState.Normal || AlwaysShowBorder)
     {
         rect.Width--;
         rect.Height--;
         if (style != RoundStyle.None)
         {
             using (var path = DrawHelper.CreateRoundPath(rect, roundWidth, style, false))
             {
                 if (ControlStates != ControlState.Normal)
                 {
                     using (
                         var brush = (ControlStates == ControlState.Pressed)
                             ? new LinearGradientBrush(rect, BaseColorEnd, BaseColor,
                                                       LinearGradientMode.ForwardDiagonal)
                             : new LinearGradientBrush(rect, BaseColor, BaseColorEnd, LinearGradientMode.Vertical)
                         )
                     {
                         if (!ShowSpliteButton)
                         {
                             g.FillPath(brush, path);
                         }
                         else
                         {
                             if (CurrentMousePosition == ButtonMousePosition.Button)
                             {
                                 using (
                                     var buttonpath = DrawHelper.CreateRoundPath(ButtonRect, roundWidth,
                                                                                 RoundStyle.Left, true))
                                 {
                                     g.FillPath(brush, buttonpath);
                                 }
                             }
                             else
                             {
                                 using (
                                     var splitepath = DrawHelper.CreateRoundPath(SpliteButtonRect, roundWidth,
                                                                                 RoundStyle.Right, true))
                                 {
                                     g.FillPath(brush, splitepath);
                                 }
                             }
                         }
                     }
                 }
                 using (var pen = new Pen(_borderColor))
                 {
                     g.DrawPath(pen, path);
                 }
             }
             rect.Inflate(-1, -1);
             using (var path = DrawHelper.CreateRoundPath(rect, roundWidth, style, false))
             {
                 using (var pen = new Pen(InnerBorderColor))
                 {
                     g.DrawPath(pen, path);
                 }
             }
         }
         else
         {
             if (ControlStates != ControlState.Normal)
             {
                 using (
                     var brush = (ControlStates == ControlState.Pressed)
                         ? new LinearGradientBrush(rect, BaseColorEnd, BaseColor,
                                                   LinearGradientMode.ForwardDiagonal)
                         : new LinearGradientBrush(rect, BaseColor, BaseColorEnd, LinearGradientMode.Vertical))
                 {
                     if (!ShowSpliteButton)
                     {
                         g.FillRectangle(brush, rect);
                     }
                     else
                     {
                         if (CurrentMousePosition == ButtonMousePosition.Button)
                         {
                             g.FillRectangle(brush, ButtonRect);
                         }
                         else
                         {
                             g.FillRectangle(brush, SpliteButtonRect);
                         }
                     }
                 }
             }
             using (var pen = new Pen(_borderColor))
             {
                 g.DrawRectangle(pen, rect);
             }
             rect.Inflate(-1, -1);
             using (var pen = new Pen(InnerBorderColor))
             {
                 g.DrawRectangle(pen, rect);
             }
         }
     }
 }
Exemplo n.º 11
0
 protected override void OnResize(EventArgs e)
 {
     base.OnResize(e);
     this.Region = new Region(DrawHelper.CreateRoundPath(Width, Height, 3));
 }
Exemplo n.º 12
0
 public static void RenderBackgroundInternal(
     Graphics g,
     Rectangle rect,
     Color baseColor,
     Color borderColor,
     Color innerBorderColor,
     RoundStyle style,
     int roundWidth,
     float basePosition,
     bool drawBorder,
     bool drawGlass,
     LinearGradientMode mode)
 {
     if (drawBorder)
     {
         rect.Width--;
         rect.Height--;
     }
     if (rect.Width == 0 || rect.Height == 0)
     {
         return;
     }
     using (var brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
     {
         Color[] colorArray =
         {
             GetColor(baseColor, 0, 0x23, 0x18, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor,
             GetColor(baseColor, 0, 0x23, 0x18, 9)
         };
         var blend    = new ColorBlend();
         var numArray = new float[4];
         numArray[1]               = basePosition;
         numArray[2]               = basePosition + 0.05f;
         numArray[3]               = 1f;
         blend.Positions           = numArray;
         blend.Colors              = colorArray;
         brush.InterpolationColors = blend;
         if (style != RoundStyle.None)
         {
             //using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             using (var path = DrawHelper.CreateRoundPath(rect, roundWidth, style, false))
             {
                 g.FillPath(brush, path);
             }
             if (drawGlass)
             {
                 if (baseColor.A > 80)
                 {
                     var rectangle = rect;
                     if (mode == LinearGradientMode.Vertical)
                     {
                         rectangle.Height = (int)(rectangle.Height * basePosition);
                     }
                     else
                     {
                         rectangle.Width = (int)(rect.Width * basePosition);
                     }
                     using (var path2 = DrawHelper.CreateRoundPath(rectangle, roundWidth, RoundStyle.Top, false))
                     //
                     {
                         using (var brush2 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff)))
                         {
                             g.FillPath(brush2, path2);
                         }
                     }
                 }
                 RectangleF glassRect = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     glassRect.Y      = rect.Y + (rect.Height * basePosition);
                     glassRect.Height = (rect.Height - (rect.Height * basePosition)) * 2f;
                 }
                 else
                 {
                     glassRect.X     = rect.X + (rect.Width * basePosition);
                     glassRect.Width = (rect.Width - (rect.Width * basePosition)) * 2f;
                 }
                 ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
             }
             if (!drawBorder)
             {
                 return;
             }
             using (var path3 = DrawHelper.CreateRoundPath(rect, roundWidth, style, false)) //
             {
                 using (var pen = new Pen(borderColor))
                 {
                     g.DrawPath(pen, path3);
                 }
             }
             rect.Inflate(-1, -1);
             using (var path4 = DrawHelper.CreateRoundPath(rect, roundWidth, style, false)) //
             {
                 using (var pen2 = new Pen(innerBorderColor))
                 {
                     g.DrawPath(pen2, path4);
                 }
                 return;
             }
         }
         g.FillRectangle(brush, rect);
         if (drawGlass)
         {
             if (baseColor.A > 80)
             {
                 var rectangle2 = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     rectangle2.Height = (int)(rectangle2.Height * basePosition);
                 }
                 else
                 {
                     rectangle2.Width = (int)(rect.Width * basePosition);
                 }
                 using (var brush3 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff)))
                 {
                     g.FillRectangle(brush3, rectangle2);
                 }
             }
             RectangleF ef2 = rect;
             if (mode == LinearGradientMode.Vertical)
             {
                 ef2.Y      = rect.Y + (rect.Height * basePosition);
                 ef2.Height = (rect.Height - (rect.Height * basePosition)) * 2f;
             }
             else
             {
                 ef2.X     = rect.X + (rect.Width * basePosition);
                 ef2.Width = (rect.Width - (rect.Width * basePosition)) * 2f;
             }
             ControlPaintEx.DrawGlass(g, ef2, 200, 0);
         }
         if (drawBorder)
         {
             using (var pen3 = new Pen(borderColor))
             {
                 g.DrawRectangle(pen3, rect);
             }
             rect.Inflate(-1, -1);
             using (var pen4 = new Pen(innerBorderColor))
             {
                 g.DrawRectangle(pen4, rect);
             }
         }
     }
 }