wpf 对话框

1.打开文件对话框
        var openFileDialog = new Microsoft.Win32.OpenFileDialog()
        {
            Filter = "avi(*.avi)|*.avi|mp4 (*.mp4)|*.mp4|wmv(*.wmv)|*.wmv"
        };
        var result = openFileDialog.ShowDialog();
        if (result == true)
        {
            System.Diagnostics.Process.Start(openFileDialog.FileName);
        }
2.选择对话框
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {}

3.保存对话框
 SaveFileDialog saveFileDialog1 = new  SaveFileDialog();

                saveFileDialog1.Filter = "txt files   (*.txt)|*.txt";
                saveFileDialog1.FilterIndex = 2;
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if ((myStream = saveFileDialog1.OpenFile()) != null)
                    {
                        using (StreamWriter sw = new StreamWriter(myStream))
                        {
                            sw.Write("this is the text");
                        }
                        
                        myStream.Close();
                        MessageBox.Show("Saved");
                    }
                } 
4.messageBox  提示对话框
            MessageBoxResult dr = MessageBox.Show("退出可能导致无法使用?"+"\r\n"+"是否退出", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
            if (dr == MessageBoxResult.OK)
            {
                //添加一些操作
            }



你可能感兴趣的:(wpf 对话框)