vb.net颜色代码 vb中颜色

vb.net里改标签背景颜色的代码是什么啊Label1.BackColor = Color.Red
Label1.BackColor = Color.Blue
Label1.BackColor = Color.Yellow
在vb 。net中 我们制作个打字程序我想在文本框里的字母中指定一个字母变颜色的代码 , 要怎么写??在TextChanged事件中:privatevoidrichTextBox1_TextChanged(objectsender,EventArgse)
{
if(label1.Text==richTextBox1.Text)
richTextBox1.ForeColor=Color.Black;
else
richTextBox1.ForeColor=Color.Red;
}-------------------继续答复:
首先,还是建议你使用TextChange方法 。KeyPress方法只有在松开键后才触发,如果一直按着键比如写a,那这串a颜色不会变的,直到你松手 。
然后上代码,测试可用的,你直接放到KeyPress里也能用:
PrivateSubrichTextBox1_TextChanged(senderAsObject,eAsEventArgs)
ForiAsInteger=0TorichTextBox1.TextLength-1
richTextBox1.SelectionStart=i
richTextBox1.SelectionLength=1
Ifi=label1.Text.LengthThen
richTextBox1.SelectionColor=Color.Blue
ElseIflabel1.Text(i)richTextBox1.Text(i)Then
richTextBox1.SelectionColor=Color.Red
Else
richTextBox1.SelectionColor=Color.Black
EndIf
Next
richTextBox1.SelectionLength=0
richTextBox1.SelectionStart=richTextBox1.TextLength
EndSub这里写错的是红色,多写出来的是蓝色,具体你自己可以调整 。
顺便鄙视一下那个把我代码直接转VB贴上来的,我直接用工具转成VB了,方便楼主参考 。
有问题可以继续追问 。
VB.NET设置屏幕分辨率、颜色位数、刷新率 实例代码这篇文章介绍了VB.NET设置屏幕分辨率、颜色位数、刷新率
实例代码,有需要的朋友可以参考一下
复制代码
代码如下:
Private
Declare
Function
GetDeviceCaps
Lib
"gdi32"
(ByVal
hdc
As
Long,
ByVal
nIndex
As
Long)
As
Long
Private
Declare
Function
ChangeDisplaySettings
Lib
"user32"
Alias
"ChangeDisplaySettingsA"
(lpDevMode
As
Any,
ByVal
dwflags
As
Long)
As
Long
Private
Const
CCDEVICENAME
As
Long
=
32
Private
Const
CCFORMNAME
As
Long
=
32
Private
Const
DM_BITSPERPEL
As
Long
=
H40000
Private
Const
DM_PELSWIDTH
As
Long
=
H80000
Private
Const
DM_PELSHEIGHT
As
Long
=
H100000
Private
Const
DM_DISPLAYFLAGS
As
Long
=
H200000
Private
Const
DM_DISPLAYFREQUENCY
=
H400000
Private
Const
CDS_FORCE
As
Long
=
H80000000
Private
Const
BITSPIXEL
As
Long
=
12
Private
Const
HORZRES
As
Long
=
8
Private
Const
VERTRES
As
Long
=
10
Private
Const
VREFRESH
=
116
Private
Type
DEVMODE
dmDeviceName
As
String
*
CCDEVICENAME
dmSpecVersion
As
Integer
dmDriverVersion
As
Integer
dmSize
As
Integer
dmDriverExtra
As
Integer
dmFields
As
Long
dmOrientation
As
Integer
dmPaperSize
As
Integer
dmPaperLength
As
Integer
dmPaperWidth
As
Integer
dmScale
As
Integer
dmCopies
As
Integer
dmDefaultSource
As
Integer
dmPrintQuality

推荐阅读