任务栏气泡提示窗口和动态显示磁盘容量图表

1、任务栏气泡提示
首先我们先设计好一个界面,如下图:
在这里插入图片描述
代码如下:
private void clewButton_Click(object sender,EventArgs e)
{
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(1000,"当前时间: ",DateTime.Now.ToLocalTime().ToString(),ToolTipIcon.Info);
}

    private void closeButton_Click(object sender,EventArgs e)
    {
        this.notifyIcon1.Visible = false;
    }

    private void notifyIcon1_MouseMove(object sender,MouseEventArgs e)
    {
        this.notifyIcon1.ShowBalloonTip(1000,"当前时间:",DateTime.Now.ToLocalTime().ToString(),ToolTipIcon.Info);
 }

效果如下图:
在这里插入图片描述

3、动态显示磁盘容量
界面如下:
在这里插入图片描述
代码如下:
private void Form1_Load(object sender, EventArgs e)
{
SelectQuery selectQuery = new SelectQuery(“select * from win32_logicaldisk”);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);
foreach (ManagementObject disk in searcher.Get())
{
comboBox1.Items.Add(disk[“Name”].ToString());
}
}

    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();
        graphics.Clear(Color.White);
        Pen pen1 = new Pen(Color.Red);
        Brush brush1 = new SolidBrush(Color.WhiteSmoke);
        Brush brush2 = new SolidBrush(Color.Red );
        Brush brush3 = new SolidBrush(Color.SteelBlue );
        Font font1 = new Font("Courier New", 16, FontStyle.Bold);
        Font font2 = new Font("宋体", 9);
        graphics.DrawString("磁盘容量分析", font1, brush2, new Point(60, 50));
        float angle1 = Convert.ToSingle((360 * (Convert.ToSingle(fsize / 100000000000) / Convert.ToSingle(tsize / 100000000000))));
        float angle2 = Convert.ToSingle((360 * (Convert.ToSingle((tsize - fsize) / 100000000000) / Convert.ToSingle(tsize / 100000000000))));
        graphics.FillPie(brush2, 60, 80, 150, 150, 0, angle1);
        graphics.FillPie(brush3, 60, 80, 150, 150, angle1, angle2);
        graphics.DrawRectangle(pen1, 30, 235, 200, 50);
        graphics.FillRectangle(brush2, 35, 245, 20, 10);
        graphics.DrawString("磁盘剩余容量:" + dinfo.TotalFreeSpace / 1000 + "KB", font2, brush2, 55, 245);
        graphics.FillRectangle(brush3, 35, 265, 20, 10);
        graphics.DrawString("磁盘已用容量:" + (dinfo.TotalSize - dinfo.TotalFreeSpace) / 1000 + "KB", font2, brush3, 55, 265);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Close();
        Application.Exit();   //退出程序
 }

效果图如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值