重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章介绍了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
1.不正确
Dim abc As myClass,定义一个可以引用myClass类型对象的变量abc。这个abc变量存在于栈上。
abc=New myClass。New myClass创建myClass实例对象,这个对象存在于托管堆上。然后(同时)让abc引用(指向)这个对象。
abc变量在栈上,而对象在托管堆上。
abc储存的是对象的地址,而不是对象本身。
看下面的代码
Dim a As myClass,b As myClass,c As myClass
a=New myClass
b=a
c=a
整个过程中只创建了一个myClass对象,位于托管堆上。
三个myClass类型的变量a、b、c位于栈上,都指向了这一个myClass对象
2.类的成员分 实例成员 和 静态成员
实例成员 必须在实例对象上调用
静态成员 可以直接调用,不需要实例对象。
该实例有很多实现方法,下面介绍一种不同的给你:
首先要在窗体中载入以下控件:progressbar(进度条),label(用来实时显示文本提示),两个timer(分别控制进度条进度的增减),然后用以下代码就能实现:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 500
Timer2.Interval = 500
ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
ProgressBar1.Minimum = 0
End Sub
'上述过程是设置控件的初始值,也可以在属性面板设置
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value += 1
Label1.Text = "当前完成" ProgressBar1.Value "%"
If (ProgressBar1.Value = 100) Then
Timer1.Enabled = False
Timer2.Enabled = True
End If
End Sub
'timer1用来控制进度的增加
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
ProgressBar1.Value -= 1
Label1.Text = "当前完成" ProgressBar1.Value "%"
If (ProgressBar1.Value = 0) Then
Timer1.Enabled = True
Timer2.Enabled = False
End If
End Sub
'time2用来控制进度的减少
End Class
就是只允许启动单一个应用程序的实例, 试图启动第二次时不会产生新的实例,并激活已经启动的实例.