zoukankan      html  css  js  c++  java
  • C#红绿状态灯

    1.在Label里 画圆,存在窗体刷新会丢失画。

      public void SetShowConnectStatus(Label lbl, bool isOk)
            {
                lbl.Text = "";
                Graphics gra = lbl.CreateGraphics();
                gra.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                Color c = isOk ? Color.Green : Color.Red;
                Brush bush = new SolidBrush(c);//填充的颜色
                gra.FillEllipse(bush, 10, 10, lbl.Width / 2, lbl.Width / 2);
    
            }

     2.在控件Paint事件里画,Invalidate 刷新。

       

      private bool isRotaryConnectOK = false;
            private void button1_Click(object sender, EventArgs e)
            {
    
                isRotaryConnectOK =!isRotaryConnectOK;
                lblRotaryConnectStatus.Invalidate();
            }
           
            private void lblRotaryConnectStatus_Paint(object sender, PaintEventArgs e)
            {
                Graphics gp = e.Graphics;
           gp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Color c
    = isRotaryConnectOK ? Color.Lime : Color.Red; SolidBrush s = new SolidBrush(c); gp.FillEllipse(s, 5, 5, lblRotaryConnectStatus.Width/2, lblRotaryConnectStatus.Width / 2); }

    void FillEllipse(Brush brush,int x,int y,int width,int height);
    其中brush为指定画刷,(x1,y1)为指定矩形的左上角坐标,width为指定矩形的宽,height为指定矩形的高。 

    添加文字:

    Font font_ = new Font("微软雅黑", 14, FontStyle.Regular);
    SolidBrush brush_ = new SolidBrush(Color.White);
    gp.DrawString(adcLsbNumber_, font_, brush_,8, 6);

  • 相关阅读:
    Nginx简单认识
    Redis简单入门认识
    用户体验报告——脉脉
    zine结构图
    猫眼电影原型图
    关于共享单车的一点思考
    用户体验报告——网易严选
    Zine和石墨文档竞品分析
    用户体验报告——石墨文档
    集合框架2
  • 原文地址:https://www.cnblogs.com/ike_li/p/9590849.html
Copyright © 2011-2022 走看看