C# WPF - 打开默认对话框操作
/// <summary> /// 打开Windows对话框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { WindowDlg windowDlg = new WindowDlg(); windowDlg.ShowDialog(); lbLogs.Items.Add(windowDlg.DialogResult); } /// <summary> /// 打开文件对话框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_1(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { lbLogs.Items.Add("打开成功:" + openFileDialog.FileName); } else { lbLogs.Items.Add("打开失败"); } } /// <summary> /// 打开保存文件对话框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_2(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); if (saveFileDialog.ShowDialog() == true) { lbLogs.Items.Add("保存成功:" + saveFileDialog.FileName); } else { lbLogs.Items.Add("保存失败"); } } /// <summary> /// 打开打印对话框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_3(object sender, RoutedEventArgs e) { PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { lbLogs.Items.Add("打印成功"); } else { lbLogs.Items.Add("打印失败"); } } /// <summary> /// 打开文字对话框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_4(object sender, RoutedEventArgs e) { FontDialog fontDialog = new FontDialog(); if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { lbLogs.Items.Add("字体选择成功:" + fontDialog.Font); } else { lbLogs.Items.Add("字体选择失败"); } } /// <summary> /// 打开颜色对话框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_5(object sender, RoutedEventArgs e) { ColorDialog colorDialog = new ColorDialog(); if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { lbLogs.Items.Add("颜色选择成功!" + colorDialog.Color); } else { lbLogs.Items.Add("颜色选择失败!"); } }
作者:Jeremy.Wu
出处:https://www.cnblogs.com/jeremywucnblog/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。