大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
您好,这种方法可以通过按钮的MouseDown和MouseUp事件来实现,比如说,当单击按钮RedColor(RedColor为这个按钮的Name属性的属性值)的时候,要使按钮的颜色变成红色,这可以在代码视图中的控件选择下拉列表中选择RedColor这个控件,然后在右边的事件下拉列表中选择MouseDown事件(当按下鼠标时发生),这时,Visual Studio会自动生成如下代码:
创新互联建站凭借在网站建设、网站推广领域领先的技术能力和多年的行业经验,为客户提供超值的营销型网站建设服务,我们始终认为:好的营销型网站就是好的业务员。我们已成功为企业单位、个人等客户提供了成都网站设计、成都网站制作服务,以良好的商业信誉,完善的服务及深厚的技术力量处于同行领先地位。
Private Sub RedColor_MouseDown(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RedColor.MouseDown
End Sub
接下来就在当前生成的代码中写入如下代码:
RedColor.BackColor = Color.FromArgb(255, 0, 0)
这句代码的作用是利用Color下的FromArgb方法来设置RGB颜色参数,在RGB颜色系统中,R代表红色,G代表绿色,B代表蓝色,根据这三种颜色的不同程度的调和,就会得到不同的颜色,如果您要得到深色的天蓝色,则可以设置FromArgb(0, 191, 255),这个颜色转换为HTML中的RGB颜色就是#00BFFF。
当然颜色还原最好是写在MouseUp事件里面,这样就不必在单击其他按钮时来还原上一次按下的按钮的颜色,在这里,为了方便描述,我们假设按钮的默认颜色为白色,也就是FromArgb方法设置为FromArgb(255, 255, 255)的时候,所标示的颜色就是白色
所以选择了RedColor按钮的MouseUp事件后,Visual Studio会自动生成下列代码:
Private Sub RedColor_MouseUp(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RedColor.MouseUp
End Sub
MouseUp的含义是当鼠标弹起时发生,所以在这个事件就可以设置按钮颜色的还原,即添加下列代码来实现:
RedColor.BackColor = Color.FromArgb(255, 255, 255)
当然,这就编写好了一个按钮按下时变色,回弹时还原的功能,至于另外一个按钮的功能,这与这个按钮的功能一样,只是代码有一些细微的差别而已,假设这个按钮的Name属性的属性值为BlueColor,相应的代码对应如下:
Private Sub BlueColor_MouseDown(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BlueColor.MouseDown
BlueColor.BackColor = Color.FromArgb(0, 0, 255) '蓝色的FromArgb
End Sub
Private Sub BlueColor_MouseDown(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BlueColor.MouseDown
BlueColor.BackColor = Color.FromArgb(255, 255, 255)
End Sub
另外,为了避免代码的冗余,可以将RedColor和BlueColor的MouseUp事件进行合并,这合并后的代码如下:
Private Sub BlueColor_MouseDown(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BlueColor.MouseDown, RedColor.MouseUp
BlueColor.BackColor = Color.FromArgb(255, 255, 255)
RedColor.BackColor = Color.FromArgb(255, 255, 255)
End Sub
当然,这个你只要分析了控件事件代码的基本结构,一切就一目了然了,控件事件代码的基本结构如下:
[作用域] Sub 事件名([参数列表]) Handles 控件事件1 [, 控件事件2, 控件事件3...]
[事件代码区域]
End Sub
如果此回答对您有帮助,别忘了采纳哦,如果没有解决您的问题,您可以在互联网上寻找更多关于此问题的解决方案,谢谢!
这东西改不了,要想改的话要在系统显示设置里修改主题。
不过如果想做的漂亮些,可以去网上找代码把整个窗体改成蓝色(随便一种颜色)然后用代码把窗体蓝色部分扣去,可以PS一个窗体图片,插到窗体上,这样这个窗体蓝色部分都被扣去了(图片里的蓝色无法扣去)只能看见一张图片,可以在上面加控件。
这篇文章介绍了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
As
Integer
dmColor
As
Integer
dmDuplex
As
Integer
dmYResolution
As
Integer
dmTTOption
As
Integer
dmCollate
As
Integer
dmFormName
As
String
*
CCFORMNAME
dmUnusedPadding
As
Integer
dmBitsPerPel
As
Integer
dmPelsWidth
As
Long
dmPelsHeight
As
Long
dmDisplayFlags
As
Long
dmDisplayFrequency
As
Long
End
Type
Private
Sub
cmdChangeDesktopMode_Click()
Dim
DM
As
DEVMODE
With
DM
.dmPelsWidth
=
CInt(txtNewWidth.Text)
.dmPelsHeight
=
CInt(txtNewHeight.Text)
.dmBitsPerPel
=
CInt(txtNewColor.Text)
.dmDisplayFrequency
=
CInt(txtNewFreq.Text)
.dmFields
=
DM_PELSWIDTH
Or
DM_PELSHEIGHT
Or
DM_BITSPERPEL
Or
DM_DISPLAYFREQUENCY
.dmSize
=
LenB(DM)
End
With
If
ChangeDisplaySettings(DM,
CDS_FORCE)
Then
MsgBox
"错误!不支持此模式!"
End
If
End
Sub
Private
Sub
Form_Load()
txtOldWidth.Text
=
GetDeviceCaps(Me.hdc,
HORZRES)
txtOldHeight.Text
=
GetDeviceCaps(Me.hdc,
VERTRES)
txtOldColor.Text
=
GetDeviceCaps(Me.hdc,
BITSPIXEL)
txtOldFreq.Text
=
GetDeviceCaps(Me.hdc,
VREFRESH)
End
Sub