/// <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/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
