实现效果:
知识运用:
API函数SHFormatDrive //用于格式化磁盘
实现代码:
[DllImport("shell32.dll")] private static extern int SHFormatDrive(IntPtr hWnd,int drive,long fmtID,int Options); private const long SHFMT_ID_DEFAULT = 0xFFFF; private void button1_Click(object sender, EventArgs e) { try { SHFormatDrive(this.Handle,this.comboBox1.SelectedIndex,SHFMT_ID_DEFAULT,0); MessageBox.Show("格式化完成","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } catch (Exception) { MessageBox.Show("格式化失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
原文地址:https://www.cnblogs.com/feiyucha/p/10306031.html
时间: 2024-11-03 05:27:49