图表显示磁盘容量

Posted on 2019-01-22 18:41  努力成长静待花开  阅读(303)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:
  Graphics类中的FillPie方法  //
用来填充由一对坐标 一个宽度 一个高度 两天射线指定的椭圆所定义的扇形的内部

  public void FilePie (Brush brush ,float x, float y, float width,float height,float startAngle ,float sweepAngle)

  

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            DriveInfo Dinfo = new DriveInfo(comboBox1.Text);
            float tsize = Dinfo.TotalSize;
            float fsize = Dinfo.TotalFreeSpace;
            Graphics graphics = this.CreateGraphics();
            Pen pen=new Pen(Color.Red);
            Brush brush2 = new SolidBrush(Color.LimeGreen);
            Brush brush3 = new SolidBrush(Color.Blue);
            Font font1 = new Font("Courier New",16,FontStyle.Bold);
            Font font2 = new Font("宋体",9);
            graphics.DrawString("磁盘容量分析",font1,brush2,70,60);
            float rangle1 = Convert.ToSingle(360 * ((fsize / 100000000) / (tsize / 100000000)));
            float rangle2 = Convert.ToSingle(360 * (((tsize - fsize) / 100000000) / (tsize / 100000000)));
            graphics.FillPie(brush2, 60, 80, 150, 150, 0, rangle1);
            graphics.FillPie(brush3, 60, 80, 150, 150,rangle1,rangle2);
            graphics.DrawRectangle(pen,60,238,180,40);
            graphics.FillRectangle(brush2,64,244,28,14);
            graphics.DrawString("磁盘剩余容量:"+fsize/1000+"KB",font2,brush2,95,244);
            graphics.FillRectangle(brush3, 64, 260, 28, 14);
            graphics.DrawString("磁盘已用容量:" + (tsize-fsize) / 1000 + "KB", font2, brush3, 95, 260);
        }