如何实现messagebox.show 的messageboxbutton.ok是英文

时间: 2023-08-12 09:07:56 浏览: 38
您可以使用以下代码来实现将MessageBoxButton.OK设置为英文: ```c# MessageBox.Show("Message", "Title", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); ``` 在这个代码中,您需要将MessageBoxButton.OK替换为MessageBoxButtons.OK,这样就可以将其设置为英文。```MessageBoxOptions.DefaultDesktopOnly```则用于在Windows桌面上显示消息框。
相关问题

using (FileStream fswrite = File.OpenWrite(path)) { wb.Write(fswrite); MessageBox.Show("导出完成!", "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); }wpf messagebox怎么2秒后自动关闭

你可以在`MessageBox.Show`之前添加`Task.Delay`来延迟2秒钟后自动关闭`MessageBox`。以下是示例代码: ``` using (FileStream fswrite = File.OpenWrite(path)) { wb.Write(fswrite); var messageBoxResult = MessageBox.Show("导出完成!", "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk); if (messageBoxResult == MessageBoxResult.OK) { await Task.Delay(2000); var activeWindow = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive); activeWindow?.Close(); } } ``` 这段代码会在`MessageBox.Show`之后等待2秒钟,然后关闭处于活动状态的窗口。请注意,这里使用`Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive)`来获取当前活动的窗口,因为MessageBox可能会弹出一个新的窗口并将其设置为活动窗口。

MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);让提示置于WPF项目的最上层

要让MessageBox提示框置于WPF项目的最上层,可以使用WindowInteropHelper类的方法来实现。 首先,添加以下命名空间引用: ```csharp using System.Windows.Interop; using System.Runtime.InteropServices; ``` 然后,在需要显示MessageBox的地方,使用下面的代码: ```csharp WindowInteropHelper helper = new WindowInteropHelper(Application.Current.MainWindow); MessageBoxOptions options = MessageBoxOptions.DefaultDesktopOnly | MessageBoxOptions.Topmost; MessageBox.Show(helper.Handle, ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, options); ``` 这样,MessageBox提示框就会置于WPF项目的最上层显示。注意,上述代码中的ex.Message和"错误"是示例,你可以根据自己的需要进行更改。

相关推荐

private void ChooseFileAutoSuggestBox_TextChanged(object sender, TextChangedEventArgs e) { var filePath = ((AutoSuggestBox)sender).Text; var filePathExtension = Path.GetExtension(filePath); if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) { if (filePathExtension == ".xlsx" || filePathExtension == ".xls") { var uiMessageBox = new MessageBox { Title = "请确认打开信息!", Content = $"你是否想打开以下路径的Excel文件{filePath}?", }; uiMessageBox.ButtonLeftClick += (sender, args) => { uiMessageBox.Close(); ChooseFileAutoSuggestBox_MouseDoubleClick(sender, args); }; uiMessageBox.ButtonLeftName = "重选"; uiMessageBox.ButtonRightClick += (sender, args) => { uiMessageBox.Close(); ExcelToDataTableToDBAndDataGrid(); }; uiMessageBox.ButtonRightName = "确认"; uiMessageBox.Show(); } else { var uiMessageBox = new MessageBox { Title = "打开错误!", Content = "该文件非Excel文件!", }; uiMessageBox.ButtonLeftClick += (sender, args) => { uiMessageBox.Close(); ChooseFileAutoSuggestBox_MouseDoubleClick(sender, args); }; uiMessageBox.ButtonLeftName = "重选"; uiMessageBox.ButtonRightClick += (sender, args) => { uiMessageBox.Close(); }; uiMessageBox.ButtonRightName = "关闭"; uiMessageBox.Show(); } } else { var uiMessageBox = new MessageBox { Title = "打开错误!", Content = "该文件不存在!", }; uiMessageBox.ButtonLeftClick += (sender, args) => { uiMessageBox.Close(); ChooseFileAutoSuggestBox_MouseDoubleClick(sender, args); }; uiMessageBox.ButtonLeftName = "重选"; uiMessageBox.ButtonRightClick += (sender, args) => { uiMessageBox.Close(); }; uiMessageBox.ButtonRightName = "关闭"; uiMessageBox.Show(); } }请优化上述代码

最新推荐

recommend-type

tensorflow-2.9.2-cp39-cp39-win-amd64.whl

python爬虫案例
recommend-type

2023年下半年计算机等级考试-公共基础-WPS-PS.zip

2023年下半年计算机等级一级考试Photoshop考点梳理 2023年下半年计算机等级一级考试WPS office考点汇总 2023年下半年计算机二级考试公共基础知识科目考点汇总 根据实际考试情况进行的总结。
recommend-type

Introduction to Data Science Data With R 英文

Introduction to Data Science Data Analysis and Prediction Algorithms with R 英文原版,完整带目录,非常好的数据分析资料,有基于R的完整数据分析过程
recommend-type

数电实验三:74LS151逻辑功能测试、74LS153逻辑功能测试、74LS153全加器、三输入多数表决电路

数电实验三:74LS151逻辑功能测试、74LS153逻辑功能测试、74LS153全加器、三输入多数表决电路
recommend-type

农业机械维修记录(表式).doc

农业机械维修记录(表式).doc
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

从键盘输入一段英文字符串,其中包含多个字母‘h',请编写程序利用正则表达式,将英文字符串中的’h'全部改为‘H’

好的,我可以帮您解决这个问题。 您可以使用 Python 编写一个程序来实现这个功能。具体步骤如下: 1. 首先导入 re 模块,这个模块是 Python 中用于处理正则表达式的模块。 2. 然后定义一个包含英文字符串的变量,例如: text = "This is a string containing multiple h's." 3. 接下来,使用 re.sub() 方法来进行替换操作。re.sub() 方法的第一个参数是正则表达式,第二个参数是替换的字符或字符串,第三个参数是被替换的字符串。在这个例子里,我们需要将所有的小写字母 h 替换成大写字母 H,所以正则表达式可以写成
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。