wpfYes/No Message Box Exit in C# 在wpf应用程序中,我们经常需要弹出对话框来让用户进行选择,例如退出询问,保存询问等等。这个时候,我们可以使用MessageBox控件弹出一个提示框,让用户进行选择。 弹出Yes/No Message Box 在wpf中,我们可以通过以下代码弹出一个 Yes/No Message Box: ...
private void No_Button_Click(object sender, RoutedEventArgs e) { _isLegal = true; Close(); Result?.Invoke(this, new MessageBoxEventArgs() { Result = new MessageResult() { IsYes=false } }); } private void Yes_Button_Click(object sender, RoutedEventArgs e) { _isLegal = true; Close(...
_messageString = message; DisplayImage(image); DisplayButtons(button); } privatevoidDisplayButtons(MessageBoxButton button){switch(button) {caseMessageBoxButton.OKCancel:caseMessageBoxButton.YesNo: _cancelVisibility = Visibility.Visible; _okVisibility = Visibility.Visible;break;//case MessageBoxButton.YesNo...
if(MessageBox.Show("If the file save fails, do you want to automatically try again?","Save file", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {// Do something here} 前面的代码显示如下所示的消息框: 处理消息框响应 ...
MessageBox.Show("检测到有版本更新,是否更新?", "标题", MessageBoxButton.YesNo, MessageBoxImage.Question); ②提示框: MessageBox.Show("当前选中了:" + listbox.SelectedItem, "标题", MessageBoxButton.OK, MessageBoxImage.Information); ③错误框: ...
MessageBoxResult result = MessageBox.Show("这里是消息内容","这是标题", MessageBoxButton.YesNo);if(result ==MessageBoxResult.Yes) {//do something}else{//do something} 打开文件对话框 //打开文件对话框Microsoft.Win32.OpenFileDialog dlg =newMicrosoft.Win32.OpenFileDialog(); ...
Visible; break; //case MessageBoxButton.YesNoCancel: // break; default: _okVisibility = Visibility.Visible; break; } } private void DisplayImage(MessageBoxImage image) { switch (image) { case MessageBoxImage.Warning: _geometry = Application.Current.Resources["PathWarning"] as Geometry; _solid...
MessageBoxResult result; result = MessageBox.Show("Do you want to leave this page?", "Navigation Request", MessageBoxButton.YesNo); // If the user doesn't want to navigate away, cancel the navigation if (result == MessageBoxResult.No) e.Cancel = true; } } } 如果...
, "Navigation Request", MessageBoxButton.YesNo); // If the user doesn't want to navigate away, cancel the navigation if (result == MessageBoxResult.No) e.Cancel = true; } } } 如果用来自 Page 的导航事件注册处理程序,就像前面的示例那样,就必须同时取消注册事件处理程序。 如果不这样做,就可能...
MsgBoxYesNo.cs: public partial class MsgBoxYesNo : Window { public MsgBoxYesNo(string message) { InitializeComponent(); txtMessage.Text = message; } private void Yes_Click(object sender, RoutedEventArgs e) { DialogResult = true; this....