好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

C#封装WINFORM groupBox重绘类

C#封装WINFORM  groupBox重绘类

using System;

using System.Drawing;

using System.Windows.Forms;

using System.Drawing.Drawing2D;

namespace groupBoxReDrawing

{

    /// <summary>

    /// groupBox重绘

    /// </summary>

    public class GroupBoxEx

    {

        private const int _CORNER_RADIUS = 50;

        public GroupBoxEx()

        {

        }

        /// <summary>

        /// groupBox重绘_圆角

        /// </summary>

        /// <param name="g"></param>

        /// <param name="gbx"></param>

        /// <returns></returns>

        public static Graphics PaintBack(System.Drawing.Graphics g, GroupBox gbx)

        {

                g.Clear(gbx.BackColor);

                Color color = Color.Black;//边框颜色

                Color color2 = Color.White;

                Pen p = new Pen(color, 1);

                int w = gbx.Width;

                int h = gbx.Height;

                Brush b = null;

                if (gbx.Parent != null)

                    b = new SolidBrush(gbx.Parent.BackColor);

                else

                    b = new SolidBrush(color);

                //绘制直线

                g.DrawLine(p, 3, h - 1, w - 4, h - 1);                     //bottom

                g.DrawLine(p, 0, h - 4, 0, 12);                            //left

                g.DrawLine(p, w - 1, h - 4, w - 1, 12);                    //right

                g.FillRectangle(b, 0, 0, w, 8);

                g.DrawLine(p, 3, 8, 10, 8);                                //lefg top

                g.DrawLine(p,                                              //right top

                    g.MeasureString(gbx.Text,

                    gbx.Font).Width + 8, 8, w - 4, 8);

                //绘制文字

                g.DrawString(gbx.Text, gbx.Font, Brushes.Blue, 10, 0);     //title

                //绘制弧线

                g.DrawArc(p, new Rectangle(0, 8, 10, 10), 180, 90);        //left top

                g.DrawArc(p, new Rectangle(w - 11, 8, 10, 10), 270, 90);   //right top

                g.DrawArc(p, new Rectangle(0, h - 11, 10, 10), 90, 90);    //left bottom

                g.DrawArc(p, new Rectangle(w - 11, h - 11, 10, 10), 0, 90);//right bottom

            return g;

        }

    }

}


查看更多关于C#封装WINFORM groupBox重绘类的详细内容...

  阅读:23次