给你一代码请你尝试,效果还过得去
VB6 SP5 WINDOWSME下调 试通过
Private Sub Form_Load()
ResiZe1 Me
End Sub
'检查屏幕的分辨率确定窗体的大小----保证窗体在不同分辨率下大小近似不变
Private Function CheckRez(pixelWidth As Long, pixelHeight As Long) As Boolean Dim lngTwipsX As Long
Dim lngTwipsY As Long lngTwipsX = pixelWidth * 15
lngTwipsY = pixelHeight * 15 If lngTwipsX <> Screen.Width Then
CheckRez = False
Else
If lngTwipsY <> Screen.Height Then
CheckRez = False
Else
CheckRez = True
End If
End IfEnd Function'获取系统显示分辨率控制在不同分辨率下大小不变
'此处只列举了640X480;1024X768与800X600
'窗体在800X600时设计
'具体请应用时灵活设计
Function XRatioFun() As Single
If CheckRez(640, 480) Then
XRatioFun = 0.8ElseIf CheckRez(1024, 768) Then
XRatioFun = 1.28
ElseIf CheckRez(800, 600) Then
XRatioFun = 1
Else
XRatioFun = 1
End If
End Function'重定位窗体与其上的控件
Sub ResiZe1(theForm As Form)
Dim Z&
Dim xfactor!
xfactor = XRatioFun
theForm.Move theForm.Left * xfactor, theForm.Top * xfactor, _
theForm.Width * xfactor, theForm.Height * xfactor For Z = 0 To theForm.Controls.Count - 1 'If TypeOf TheForm.Controls(Z) Is CommonDialog Then
'如果在窗体上有运行时不可见的ACTIVEX控件不要移动,比如IMAGELIST与CommonDialog等等
'If TypeOf theForm.Controls(Z) Is ImageList Then
If TypeOf theForm.Controls(Z) Is Menu Then
'菜单系统会自动处理
ElseIf TypeOf theForm.Controls(Z) Is Line Then
'直线控件不要处理
ElseIf TypeOf theForm.Controls(Z) Is DriveListBox Then
theForm.Controls(Z).Move theForm.Controls(Z).Left * xfactor, _
theForm.Controls(Z).Top, theForm.Controls(Z).Width * xfactor
ElseIf TypeOf theForm.Controls(Z) Is ComboBox Then
If theForm.Controls(Z).Style <> 1 Then
theForm.Controls(Z).Move theForm.Controls(Z).Left * xfactor, _
theForm.Controls(Z).Top * xfactor, theForm.Controls(Z).Width * _
xfactor
End If
ElseIf Not theForm.Controls(Z) Is Nothing Then
theForm.Controls(Z).Move theForm.Controls(Z).Left * xfactor, _
theForm.Controls(Z).Top * xfactor, theForm.Controls(Z).Width _
* xfactor, theForm.Controls(Z).Height * xfactor If TypeOf theForm.Controls(Z) Is TextBox Then
theForm.Controls(Z).FontSize = theForm.Controls(Z).FontSize * xfactor
ElseIf TypeOf theForm.Controls(Z) Is Label Then
theForm.Controls(Z).FontSize = theForm.Controls(Z).FontSize * xfactor
End If
End If
Next ZEnd Sub
VB6 SP5 WINDOWSME下调 试通过
Private Sub Form_Load()
ResiZe1 Me
End Sub
'检查屏幕的分辨率确定窗体的大小----保证窗体在不同分辨率下大小近似不变
Private Function CheckRez(pixelWidth As Long, pixelHeight As Long) As Boolean Dim lngTwipsX As Long
Dim lngTwipsY As Long lngTwipsX = pixelWidth * 15
lngTwipsY = pixelHeight * 15 If lngTwipsX <> Screen.Width Then
CheckRez = False
Else
If lngTwipsY <> Screen.Height Then
CheckRez = False
Else
CheckRez = True
End If
End IfEnd Function'获取系统显示分辨率控制在不同分辨率下大小不变
'此处只列举了640X480;1024X768与800X600
'窗体在800X600时设计
'具体请应用时灵活设计
Function XRatioFun() As Single
If CheckRez(640, 480) Then
XRatioFun = 0.8ElseIf CheckRez(1024, 768) Then
XRatioFun = 1.28
ElseIf CheckRez(800, 600) Then
XRatioFun = 1
Else
XRatioFun = 1
End If
End Function'重定位窗体与其上的控件
Sub ResiZe1(theForm As Form)
Dim Z&
Dim xfactor!
xfactor = XRatioFun
theForm.Move theForm.Left * xfactor, theForm.Top * xfactor, _
theForm.Width * xfactor, theForm.Height * xfactor For Z = 0 To theForm.Controls.Count - 1 'If TypeOf TheForm.Controls(Z) Is CommonDialog Then
'如果在窗体上有运行时不可见的ACTIVEX控件不要移动,比如IMAGELIST与CommonDialog等等
'If TypeOf theForm.Controls(Z) Is ImageList Then
If TypeOf theForm.Controls(Z) Is Menu Then
'菜单系统会自动处理
ElseIf TypeOf theForm.Controls(Z) Is Line Then
'直线控件不要处理
ElseIf TypeOf theForm.Controls(Z) Is DriveListBox Then
theForm.Controls(Z).Move theForm.Controls(Z).Left * xfactor, _
theForm.Controls(Z).Top, theForm.Controls(Z).Width * xfactor
ElseIf TypeOf theForm.Controls(Z) Is ComboBox Then
If theForm.Controls(Z).Style <> 1 Then
theForm.Controls(Z).Move theForm.Controls(Z).Left * xfactor, _
theForm.Controls(Z).Top * xfactor, theForm.Controls(Z).Width * _
xfactor
End If
ElseIf Not theForm.Controls(Z) Is Nothing Then
theForm.Controls(Z).Move theForm.Controls(Z).Left * xfactor, _
theForm.Controls(Z).Top * xfactor, theForm.Controls(Z).Width _
* xfactor, theForm.Controls(Z).Height * xfactor If TypeOf theForm.Controls(Z) Is TextBox Then
theForm.Controls(Z).FontSize = theForm.Controls(Z).FontSize * xfactor
ElseIf TypeOf theForm.Controls(Z) Is Label Then
theForm.Controls(Z).FontSize = theForm.Controls(Z).FontSize * xfactor
End If
End If
Next ZEnd Sub
自己在ReSize事件中处理控件的坐标