Public?Class?Form1
創(chuàng)新互聯(lián)公司為您提適合企業(yè)的網(wǎng)站設(shè)計(jì)?讓您的網(wǎng)站在搜索引擎具有高度排名,讓您的網(wǎng)站具備超強(qiáng)的網(wǎng)絡(luò)競(jìng)爭(zhēng)力!結(jié)合企業(yè)自身,進(jìn)行網(wǎng)站設(shè)計(jì)及把握,最后結(jié)合企業(yè)文化和具體宗旨等,才能創(chuàng)作出一份性化解決方案。從網(wǎng)站策劃到成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè), 我們的網(wǎng)頁(yè)設(shè)計(jì)師為您提供的解決方案。
Dim 初始化控件自動(dòng)大小調(diào)整與窗口的寬度比例 As Integer
Dim 初始化控件自動(dòng)大小調(diào)整與窗口的高度比例 As Integer
Private?Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
初始化控件自動(dòng)大小調(diào)整與窗口的寬度比例 = Me.Width / 控件自動(dòng)大小調(diào)整.Width
初始化控件自動(dòng)大小調(diào)整與窗口的高度比例 = Me.Height / 控件自動(dòng)大小調(diào)整.Height
顯示控件的位置坐標(biāo)()
End?Sub
Private?Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
' Form1_ResizeEnd? 這個(gè)事件是 窗口大小變化完成后 再進(jìn)行操作的
控件自動(dòng)大小調(diào)整.Location = New Point(控件自動(dòng)大小調(diào)整.Left, 控件自動(dòng)大小調(diào)整.Top)
'設(shè)置控件的初始左位置坐標(biāo)? 與? 上位置坐標(biāo)
控件自動(dòng)大小調(diào)整.Size = New Point(Int(Me.Width / 初始化控件自動(dòng)大小調(diào)整與窗口的寬度比例), Int(Me.Height / 初始化控件自動(dòng)大小調(diào)整與窗口的高度比例))
'更改控件的大小? 按第一次窗口的比例 進(jìn)行調(diào)整
顯示控件的位置坐標(biāo)()
End Sub
Private?Sub 顯示控件的位置坐標(biāo)()
Label1.Text = "控件的上邊距坐標(biāo): " 控件自動(dòng)大小調(diào)整.Top
Label2.Text = "控件的左邊距坐標(biāo): " 控件自動(dòng)大小調(diào)整.Left
Label3.Text = "控件的寬度大?。?" 控件自動(dòng)大小調(diào)整.Width
Label4.Text = "控件的高度大小: " 控件自動(dòng)大小調(diào)整.Height
End Sub
End?Class
默認(rèn)單位是像素
96是系統(tǒng)的一種設(shè)定,每英寸的點(diǎn)數(shù),是系統(tǒng)界面用小字體時(shí)的設(shè)置
用像素?cái)?shù)除以DPI沒有意義
您可以用下面給出這一小段代碼檢測(cè)當(dāng)前屏幕分辨率,然后根據(jù)結(jié)果作出反應(yīng)──例如,重新調(diào)整窗體大小以適應(yīng)用程序戶分辨率。
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
這篇文章介紹了VB.NET設(shè)置屏幕分辨率、顏色位數(shù)、刷新率
實(shí)例代碼,有需要的朋友可以參考一下
復(fù)制代碼
代碼如下:
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
"錯(cuò)誤!不支持此模式!"
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