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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM