新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章介绍了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
Label1.BackColor = Color.Red
Label1.BackColor = Color.Blue
Label1.BackColor = Color.Yellow
TextBox1.ForeColor = Color.Red
TextBox1.BackColor = Color.Yellow
TextBox1.Text = 1234
您好,这种方法可以通过按钮的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
如果此回答对您有帮助,别忘了采纳哦,如果没有解决您的问题,您可以在互联网上寻找更多关于此问题的解决方案,谢谢!