Winform开发遇到的问题之控件重绘[针对边框颜色]

1.代码块:

        //重绘方法(Paint)
        private void txt_Paint(object sender, PaintEventArgs e)
        {
            //读取配置文件的宽和高
            int x =Convert.ToInt32(AppConfig.width);
            int y = Convert.ToInt32(AppConfig.height);
            DrawBorder(e.Graphics, Color.Transparent, Color.Red, x,y);
        }

        private SolidBrush SegBrush; //   功控填充颜色所用brush  

        /// <summary>
        /// //绘制边框 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="color">lable背景颜色</param>
        /// <param name="color">边框颜色</param>
        /// <param name="x">label宽度</param>
        /// <param name="y">label高度</param>
        private void DrawBorder(System.Drawing.Graphics g, Color color, Color bordercolor, int x, int y)
        {

            SegBrush = new SolidBrush(color);
            Pen pen = new Pen(SegBrush, 1);
            txt.BorderStyle = BorderStyle.None;
            txt.BackColor = color;
            pen.Color = Color.White;
            Rectangle myRectangle = new Rectangle(0, 0, x, y);
            ControlPaint.DrawBorder(g, myRectangle, bordercolor, ButtonBorderStyle.Solid);//画个边框 
        }



        //调用重绘方法,以Lable控件
        Lable txt = new Lable();
        txt.Paint +=txt_Paint;

2.效果图:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_31453627/article/details/82108616