如何使用代码更改 vb.net 中的标签颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22959867/
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
How to change label color in vb.net using codes?
提问by Ya3goobs
I want to know how to change the color of a label using its code, something like:
我想知道如何使用其代码更改标签的颜色,例如:
dim r as color
r = color.red
How do I use or assign that code to a label from a button...? Like in my form button and a label.. when the button is clicked the label changes its color .. how do I do that in vb.net?.
如何使用该代码或将该代码分配给按钮上的标签...?就像在我的表单按钮和标签中一样......当按钮被点击时标签会改变它的颜色......我如何在 vb.net 中做到这一点?
Here is my button
这是我的按钮
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim r As Color
r = Color.Red
End Sub
End Class
??
??
采纳答案by makemoney2010
You have defined a variable which is not the right way to do it. A label exposes some properties and to achieve your goal you simply do this:
您定义了一个变量,这不是正确的方法。标签公开了一些属性,为了实现您的目标,您只需执行以下操作:
Label1.BackColor = Color.Aqua
回答by Otema
First add the following import statement to the top of your class
首先将以下导入语句添加到您的类的顶部
Imports System.Drawing
Then use this code
然后使用此代码
label1.BackColor=Color.Red
回答by King of kings
Use BackColor property
使用 BackColor 属性
label1.BackColor=Color.Red