vb.net Visual Basic 中 MsgBox 的粗体字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14840843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:19:11  来源:igfitidea点击:

Bold font for MsgBox in Visual Basic

vb.net

提问by Simbox97

How to make font bold in a MessageBox in Visual Basic 2008?

如何在 Visual Basic 2008 的 MessageBox 中设置粗体字体?

I would like to have it like this:

我想像这样:

MsgBox(Documentation: .........) 

where "Documentation" will be showing in a bold font.

其中“文档”将以粗体显示。

回答by David Venegoni

As aphoria said, VB's MsgBox does not allow bold text. Here is how you work around that:

正如 aphoria 所说,VB 的 MsgBox 不允许使用粗体文本。以下是您解决此问题的方法:

1) Add a "New Windows Form" 2) Add a RichTextBox 3) Add the # of CommandButtons you want/need 4) Go to the code for the form and do something like the following

1) 添加“新 Windows 窗体” 2) 添加 RichTextBox 3) 添加您想要/需要的命令按钮数量 4) 转到窗体的代码并执行如下操作

Public Sub CustomMessageBox(ByVal msg As String, ByVal isBold As Boolean, ByVal color As System.Drawing.Color, ByVal buttonOneText As String, ByVal buttonTwoText As String, ByVal startBoldAt As Integer = 0, ByVal endBoldAt As Integer = 0)
 ' Use parameters to pass the values you want to show
 ' startBoldAt will be the position in the string where you want to have bold lettering begin, and endBoldAt will be the position in the string where you want bold lettering to end.
End Sub

Then you can do:  
Dim cmb as CustomMessageBox = New CustomMessageBox('Your parameters)
' Add a sub that will let you show the CustomMessageBox
cmb.Show()

Hope that helps.

希望有帮助。

回答by aphoria

The built-in MsgBoxfunction cannot do this. You will have to build your own if you really need it.

内置MsgBox函数无法做到这一点。如果你真的需要它,你将不得不建立自己的。