关闭

C#绘制Label边框

4782人阅读 评论(0) 收藏 举报

      using System.Drawing;

private void label1_Paint(object sender, PaintEventArgs e)
        {
          
           DrawBorder(e.Graphics, Color.Red,Color.Blue, label1.Width, label1.Height);

         }

       
          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);
            //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, bordercolor, ButtonBorderStyle.Solid);//画个边框
           // g.DrawRectangle(pen, myRectangle);
            //g.DrawEllipse(pen, myRectangle);
        }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:138507次
    • 积分:1800
    • 等级:
    • 排名:千里之外
    • 原创:22篇
    • 转载:65篇
    • 译文:1篇
    • 评论:37条
    文章分类
    源码网站