vb.net 如何更改文本颜色。简单的?

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

How to change the text color. Simple?

vb.net

提问by jruder

If CDbl(totalAverage) >= 89 Then
            lblGrade.Text = "A"
        ElseIf CDbl(totalAverage) >= 79 Then
            lblGrade.Text = "B"
        ElseIf CDbl(totalAverage) >= 69 Then
            lblGrade.Text = "C"
        ElseIf CDbl(totalAverage) >= 59 Then
            lblGrade.Text = "D"
        ElseIf CDbl(totalAverage) >= 0 Then
            lblGrade.Text = "F"
        End If

Just trying to change the colors of the text to green for an A, B, or C. Orange for a D, and red for an F.

只是尝试将 A、B 或 C 的文本颜色更改为绿色。 D 为橙色,F 为红色。

I was thinking it was lblGrade.Text.Color or something like that; however, that didn't seem to be a command and I've been looking around and was having trouble finding the answer to this and thought it would be easier to just ask here. Thanks for the help

我在想它是 lblGrade.Text.Color 或类似的东西;然而,这似乎不是一个命令,我一直在环顾四周,但在找到答案时遇到了麻烦,并认为在这里提问会更容易。谢谢您的帮助

回答by Gavin Perkins

lblGrade.Forecolor is what your looking for.

lblGrade.Forecolor 正是您要找的。

For orange, it would be "lblGrade.ForeColor = Color.Orange"

对于橙色,它将是“lblGrade.ForeColor = Color.Orange”