📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
namespace GetStorageCard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(DeviceMemoryInfo.FreeBytesAvailable.ToString() + "Total free:" + DeviceMemoryInfo.TotalFreeBytes + "Total bytes" + DeviceMemoryInfo.TotalBytes, "for Windows");
}
private void Form1_Load(object sender, EventArgs e)
{
this.grpStorage.Text = "Memory Space View";
this.progressBar21.Maximum = 100;
this.progressBar21.Minimum = 0;
this.progressBar21.DrawStyle = OpenNETCF.Windows.Forms.DrawStyle.Gradient;
DisplayMemorySattus();
}
private void DisplayMemorySattus()
{
try
{
long percentage = Math.Abs((DeviceMemoryInfo.FreeBytesAvailable * 100) / DeviceMemoryInfo.TotalBytes);
this.progressBar21.Value = (int)percentage;
double dvalue = Math.Round(Convert.ToDouble(DeviceMemoryInfo.TotalBytes / 1048576.0), 2);
this.lblTotal.Text = "TotalStorage : " + dvalue.ToString() + " MB";
long usedinKb = DeviceMemoryInfo.TotalBytes - DeviceMemoryInfo.FreeBytesAvailable;
double usedinMB = Math.Round(Convert.ToDouble(usedinKb / 1048576.0), 2);
this.lblUsed.Text = "Used Size : " + usedinMB.ToString() + " MB";
}
catch (DivideByZeroException dex)
{
MessageBox.Show(dex.Message, "Error");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void button21_Click(object sender, EventArgs e)
{
this.DisplayMemorySattus();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -