MessageBoxButtons的文字可不可以修改
时间: 2023-10-11 17:09:40 浏览: 39
`MessageBoxButtons`中的文字是预定义的,无法直接修改。如果需要自定义按钮上的文本,可以使用`MessageBox.Show`重载方法,手动构造一个包含自定义按钮的消息框。
例如,以下代码创建了一个包含“重试”,“跳过”和“取消”三个按钮的消息框:
```csharp
DialogResult result = MessageBox.Show("出现错误,是否重试?", "错误", MessageBoxButtonsCustom(
new string[] { "重试", "跳过", "取消" }
));
...
private MessageBoxButtons MessageBoxButtonsCustom(string[] buttons)
{
// 构造自定义按钮
MessageBoxButtons messageBoxButtons = 0;
foreach (string button in buttons)
{
switch (button)
{
case "确定":
messageBoxButtons |= MessageBoxButtons.OK;
break;
case "取消":
messageBoxButtons |= MessageBoxButtons.Cancel;
break;
case "重试":
messageBoxButtons |= MessageBoxButtons.Retry;
break;
case "是":
messageBoxButtons |= MessageBoxButtons.YesNo;
break;
case "否":
messageBoxButtons |= MessageBoxButtons.YesNo;
break;
case "跳过":
messageBoxButtons |= MessageBoxButtons.Ignore;
break;
default:
break;
}
}
return messageBoxButtons;
}
```
在`MessageBoxButtonsCustom`方法中,我们首先根据传入的按钮文本构造一个`MessageBoxButtons`枚举类型,然后将其作为`MessageBox.Show`方法的第三个参数。这样就可以创建一个包含自定义按钮的消息框了。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)