1. 程式人生 > >wpf 對話方塊

wpf 對話方塊

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