格式化磁盘

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

实现效果:

  

知识运用:

  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);
            }
        }