NET 怎样使界面自适应WINDOWS的不同系统和不同分辨率的屏幕?
#Region " Public Sub AutoCtlSize(ByVal inObj As Control) '自动调整控件大小"
Public Sub AutoCtlSize(ByVal inObj As Control) '自动调整控件大小
If inObj Is Nothing Then
Exit Sub
End If
'显示分辨率与窗体工作区的大小的关系:分辨率width*height--工作区(没有工具栏)width*(height-46)
'即分辨率为*600时,子窗体只能为*554
'上述情况还要windows状态栏自动隐藏,如果不隐藏,则height还要...全部
#Region " Public Sub AutoCtlSize(ByVal inObj As Control) '自动调整控件大小"
Public Sub AutoCtlSize(ByVal inObj As Control) '自动调整控件大小
If inObj Is Nothing Then
Exit Sub
End If
'显示分辨率与窗体工作区的大小的关系:分辨率width*height--工作区(没有工具栏)width*(height-46)
'即分辨率为*600时,子窗体只能为*554
'上述情况还要windows状态栏自动隐藏,如果不隐藏,则height还要减少,结果为:*524
'检测桌面显示分辨率(Visual Basic)请参见
'此示例以像素为单位确定桌面的宽度和高度。
Dim DeskTopSize As Size = System。Windows。Forms。SystemInformation。PrimaryMonitorSize
Dim FontSize As Single
FontSize = 9 * DeskTopSize。
Height / 600
'控件本身****
'控件大小
inObj。Size = New Size(Int(inObj。Size。Width * DeskTopSize。
Width / 800), Int(inObj。Size。Height * DeskTopSize。Height / 600))
'控件位置
inObj。Location = New Point(Int(inObj。
Location。X * DeskTopSize。Width / 800), Int(inObj。Location。Y * DeskTopSize。Height / 600))
'如果控件为Form,则设置固定边框
'Dim mType As Type
'Dim mProperty As System。
Reflection。PropertyInfo
'mType = inObj。GetType
'mProperty = mType。GetProperty("FormBorderStyle")
'If Not mProperty Is Nothing Then
'MessageBox。
Show(mType。ToString)
' mProperty。SetValue(inObj, FormBorderStyle。FixedSingle, Nothing)
'End If
'子控件=====
Dim n As Integer
For n = 0 To inObj。
Controls。Count - 1
'只调整子控件的字体。(如果调整窗体的字体,再调用窗体的show方法时,会引发resize从而导致控件的大小和布局改变)
inObj。
Controls。Item(n)。Font = New Font(inObj。Controls。Item(n)。Font。FontFamily, FontSize)
'递归调用(穷举所有子控件)
AutoCtlSize(inObj。
Controls。
Item(n))
Next
End Sub
#End Region 我早年写的自动调整控件大小的程序,在要show form时,通过调用AutoCtlSize(form),可以起到调整form及form中控件大小、位置的作用,你可以参考下。收起