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)
            {
                //添加一些操作
            }



  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值