好得很程序员自学网

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

C#中Winfrom开发加载绑定重绘GroupBox圆角、颜色的事件

C#中Winfrom开发加载绑定重绘GroupBox圆角、颜色的事件

加载绑定重绘事件:groupBox1.Paint += GroupBox_Paint;

        /// <summary>

        /// GroupBox重绘事件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void GroupBox_Paint(object sender, PaintEventArgs e)

        {

            if (sender != null && sender is GroupBox)

            {

                System.Drawing.Graphics g = e.Graphics;

                GroupBox gbx = sender as GroupBox;

                //重绘圆角、颜色

                PaintBack(g, gbx);

            }

        }

        /// <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#中Winfrom开发加载绑定重绘GroupBox圆角、颜色的事件的详细内容...

  阅读:20次