Winform与WPF对话框(MessageBox, Dialog)之比较

Posted lonelyxmas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Winform与WPF对话框(MessageBox, Dialog)之比较相关的知识,希望对你有一定的参考价值。

原文:Winform与WPF对话框(MessageBox, Dialog)之比较

Winform:使用System.Windows.Forms命名空间中相应控件; WPF则调用Microsoft.Win32。

MessageBox:
// WinForm
        private void WFMessageBoxClicked(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.MessageBox.Show("Hello from Windows Forms!", "Hello World!");
        }

// WPF
        private void WPFMessageBoxClicked(object sender, RoutedEventArgs e)
        {
            System.Windows.MessageBox.Show("Hello from WPF!", "Hello world!");
        }

OpenFileDialog / SaveFileDialog:

// WinForm
        private void WinFormsDialogClicked(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dialogOpenFile = new System.Windows.Forms.OpenFileDialog();
            dialogOpenFile.ShowDialog();

            //System.Windows.Forms.SaveFileDialog dialogSaveFile = new System.Windows.Forms.SaveFileDialog();
            //dialogSaveFile.ShowDialog();
        }

// WPF
        private void WPFDialogClicked(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dialogOpenFile = new Microsoft.Win32.OpenFileDialog();
            dialogOpenFile.ShowDialog();

            //Microsoft.Win32.SaveFileDialog dialogSaveFile = new Microsoft.Win32.SaveFileDialog();
            //dialogSaveFile.ShowDialog();
        }

以上是关于Winform与WPF对话框(MessageBox, Dialog)之比较的主要内容,如果未能解决你的问题,请参考以下文章

winform中为啥return后还继续执行?

关于WinForm中对话框MessageBox的问题

wpf messagebox 的返回值如何获取

如何在 WPF 中将 MessageBox 窗口保留在前台

C# winform中如果实现播放视频功能

有关winform和wpf问题对于一段代码每隔几秒执行一次的问题