码迷,mamicode.com
首页 > Windows程序 > 详细

c# winform Label 边框 背景 颜色

时间:2020-06-18 16:01:51      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:highlight   border   cti   winform   label   form   elb   oid   send   

  private void label1_Paint(object sender, PaintEventArgs e)
        {
            Label label1 = (Label)sender;
            DrawBorder(label1, e.Graphics, Color.Transparent, label1.Width, label1.Height);

        }

        private Color labelBorderColor = Color.Black;
        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(Label label1,System.Drawing.Graphics g, Color color, int x, int y)
        {


            SegBrush = new SolidBrush(color);
            Pen pen = new Pen(SegBrush, 1);
            //e.Graphics.FillRectangle(SegBrush, RcTime);

            label1.BorderStyle = BorderStyle.None;
            label1.BackColor = color;
          
            pen.Color = Color.White;

            Rectangle myRectangle = new Rectangle(0, 0, x, y);
            ControlPaint.DrawBorder(g, myRectangle, labelBorderColor, ButtonBorderStyle.Solid);//画个边框
                                                                                          // g.DrawRectangle(pen, myRectangle);
                                                                                          //g.DrawEllipse(pen, myRectangle);
        }

  

c# winform Label 边框 背景 颜色

标签:highlight   border   cti   winform   label   form   elb   oid   send   

原文地址:https://www.cnblogs.com/Betty-IT/p/13157770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!