扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
首先你要熟悉API函数,具体用哪些函数就不记得了~~~~~
我们提供的服务有:成都网站设计、成都网站制作、微信公众号开发、网站优化、网站认证、庐江ssl等。为成百上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的庐江网站制作公司
其次,把你要用到API函数引用到代码中来,就可以用了啊
VB里貌似这段代码挺多的,需要好好研究
C#中,可以通过
“
winform窗体分辨率问题解决方案:
你也可以选择使用TableLayoutPanel等控件作为容器,把其他的控件放入Panel中,这个控件会使其中包含的控件随着程序环境的变化而变化。
注:TableLayoutPanel和Panel控件的DOCK属性应该都设为:fill。
”
的方法来实现~~~~~~~~~~·
Option Explicit
'将屏幕长度(高度)的总缇数处以水平(Screen.TwipsPerPixelX)
'或垂直(Screen.TwipsPerPixelY)度量对象的每一像素缇数,就得到了相应方向的像素数。
'分别定义初始时候的屏幕宽和高,以及工程的宽和高
Dim pk As Single, pg As Single, fw As Single, fh As Single
Private Sub Command1_Click()
Dim x, y
x = Screen.Width / Screen.TwipsPerPixelX
y = Screen.Height / Screen.TwipsPerPixelY
MsgBox "你的电脑分辨率是 " x "*" y
End
End Sub
Private Sub Command2_Click() ' 让程序鼠标怎么按都没有用
Me.Enabled = False
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) '按F6退出
If KeyCode = vbKeyF6 Then Unload Me
End Sub
Private Sub Form_Load()
fw = Me.Width
fh = Me.Height
pk = Screen.Width
pg = Screen.Height
Timer1.Interval = 1000
End Sub
'我记得有个API函数的,可是具体的方法不记得了。所以就用一个timer来实时监控分辨率的··
'Set ddSet = dxSet.DirectDrawCreate("")
'dxSet建立DirectDraw对象ddSet
'ddSet.SetCooperativeLevel Me.hWnd, DDSCL_NORMAL
'设置协作水平
'Set DisModesEnum = ddSet.GetDisplayModesEnum(DDEDM_DEFAULT, dds2)
'DisModesEnum获得支持的显示模式
Private Sub Timer1_Timer()
If Screen.Width pk Or Screen.Height pg Then
Me.Width = fw / pk * Screen.Width
Me.Height = fh / pg * Screen.Height
End If
End Sub
您可以用下面给出这一小段代码检测当前屏幕分辨率,然后根据结果作出反应──例如,重新调整窗体大小以适应用程序户分辨率。
Public Function CheckRez(pixelWidth As Long, pixelHeight As Long) As Boolean
'
Dim lngTwipsX As Long
Dim lngTwipsY As Long
'
' convert pixels to twips
lngTwipsX = pixelWidth * 15
lngTwipsY = pixelHeight * 15
'
' check against current settings
If lngTwipsX Screen.Width Then
CheckRez = False
Else
If lngTwipsY Screen.Height Then
CheckRez = False
Else
CheckRez = True
End If
End If
'
End Function
Next, run the following code at the start of the program:
If CheckRez(640, 480) = False Then
MsgBox "Incorrect screen size!"
Else
MsgBox "Screen Resolution Matches!"
End If
Me.Height = My.Computer.Screen.Bounds.Height
Me.Width = My.Computer.Screen.Bounds.Width
这是设置窗体的长宽和屏幕的分辨率一样大小,相当于全屏。
如果Me.WindowState=FormWindowState.Maximized的话,只是单纯的将窗体最大化,但恢复窗口大小后窗体的大小实际上还和原来一样大。
默认单位是像素
96是系统的一种设定,每英寸的点数,是系统界面用小字体时的设置
用像素数除以DPI没有意义
这篇文章介绍了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
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流