vba 如何在 Visual Basic 中给文本加下划线(使用 Visual Studio 2010)

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

How to underline text in Visual Basic (with Visual Studio 2010)

visual-studio-2010vba

提问by caro

I have a problem with underline text after press a button in Visual Basic. I'm using Visual Studio 2010 and I red in tutorial that in button method I have to use for example:

在 Visual Basic 中按下按钮后,下划线文本出现问题。我正在使用 Visual Studio 2010 并且我在教程中红色,在按钮方法中我必须使用例如:

lbltext.FontUnderline = True

But I don't have variable "FontUnderline". Of course I was trying to find other variable or function to do this but without success. Anyone know how to do this in Visual Studio?

但我没有变量“FontUnderline”。当然,我试图找到其他变量或函数来做到这一点,但没有成功。任何人都知道如何在 Visual Studio 中执行此操作?

回答by Tony Hopkinson

Or the old way of doing it was to instance a new font

或者旧的方法是实例化一个新字体

Font standardFont = new Font(lblText.Font)
Font underFont = new Font(standardFont,FontStyle.Underline)

Then just set the Font property of the relevant controls to the one you want.

然后只需将相关控件的 Font 属性设置为您想要的。

回答by Matthis Kohli

Took the example of @Tony Hopkinson and added some small changes to make this work for VB.NET

以@Tony Hopkinson 为例,并添加了一些小的更改以使其适用于 VB.NET

So this is the syntax for VB.NET

所以这是 VB.NET 的语法

Dim standardFont As Font = lblExportDate.Font
Dim underFont As New Font(standardFont, FontStyle.Underline)

Me.lblExportDate.Font = underFont

回答by Nitram

I think you are missing a dot here.

我认为你在这里遗漏了一个点。

It should be lbltext.Font.Underline = true

它应该是 lbltext.Font.Underline = true

回答by wpcoder

An inline answer looks like this:

内联答案如下所示:

Me.lbltext.Font =  New Font(lbltext.Font, FontStyle.Underline)

This would save multiple lines of code.

这将节省多行代码。