vb.net 如何使标签的一部分加粗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18085853/
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 14:34:17  来源:igfitidea点击:

How to make a part of a label bold

vb.netlabelbold

提问by phalanx

I want to make bold just the "name" in the string, how to do it?

我只想将字符串中的“名称”加粗,该怎么做?

Dim name As String = Environment.UserName
LabelWelcome.Text = "Welcome " + name + ", ...!"

回答by Matt B-L

I don't believe this is do-able on default labels since there is no style formatting.

我不相信这在默认标签上是可行的,因为没有样式格式。

I suggest to use 2 labels or a rich text box control.

我建议使用 2 个标签或富文本框控件。

回答by Rahul Tripathi

You can use two labels and put them side by side. One having the bold part and other having the simple text.

您可以使用两个标签并将它们并排放置。一个有粗体部分,另一个有简单的文本。

You can use the OnPaint()method for custom drawing also

您也可以使用OnPaint()自定义绘图的方法

回答by NoWayIn

I found this : http://pastebin.com/L4xScMjZ[Not made by me]
It's a class that highlights part of a label for you. It doesn't bold it, but you can highlight the important part in red or any color you want.
I'm sure you could turn this to make the highlighted part bold as well.
To use it, you create a new class and put that code in.
Build your project and there should be a new control called "Scrolling Label"
You can add that control to your project and edit the properties :
Highlight : # --> how many characters you want it to highlight from left to right
HighLightText --> The color of the highlighted text
This is a bit buggy so you might want to add "DoubleBuffer = True" in your form Load

我发现了这个:http: //pastebin.com/L4xScMjZ[不是我做的]
这是一个为你突出显示部分标签的类。它没有加粗,但您可以用红色或任何您想要的颜色突出显示重要部分。
我相信您也可以将其转为加粗突出显示的部分。
要使用它,您需要创建一个新类并将该代码放入。
构建您的项目,应该有一个名为“滚动标签”的新控件
您可以将该控件添加到您的项目并编辑属性:
突出显示:# --> how您希望它从左到右突出显示的许多字符
HighLightText --> 突出显示文本的颜色
这有点问题,因此您可能希望在表单中添加“DoubleBuffer = True” 加载