请教,VB中控件位置及大小自动适应窗体变化的问题。谢谢
在网上找了个代码如下,运行后未最大化时如第一幅图,最大化后如图2,请问该如何修改代码使各个控件显示正常?新手,分不多,真心求教OptionExplicitPrivateO...
在网上找了个代码如下,运行后未最大化时如第一幅图,最大化后如图2,请问该如何修改代码使各个控件显示正常?新手,分不多,真心求教
Option Explicit Private ObjOldWidth As Long Private ObjOldHeight As Long Private ObjOldFont As Single Private Sub Form_Resize() Call ResizeForm(Me) End SubPrivate Sub Form_Load() Call ResizeInit(Me) End Sub
Public Sub ResizeInit(FormName As Form)
Dim Obj As Control
ObjOldWidth = FormName.ScaleWidth ObjOldHeight = FormName.ScaleHeight ObjOldFont = FormName.Font.Size / ObjOldHeight On Error Resume Next For Each Obj In FormName Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " " Next Obj
On Error GoTo 0 End Sub Public Sub ResizeForm(FormName As Form) Dim Pos(4) As Double Dim i As Long, TempPos As Long, StartPos As Long Dim Obj As Control Dim ScaleX As Double, ScaleY As Double
ScaleX = FormName.ScaleWidth / ObjOldWidth ScaleY = FormName.ScaleHeight / ObjOldHeight On Error Resume Next
For Each Obj In FormName StartPos = 1 For i = 0 To 4 TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare) If TempPos > 0 Then Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos) StartPos = TempPos + 1 Else Pos(i) = 0 End If
Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY Obj.Font.Size = ObjOldFont * FormName.ScaleHeight Next i
Next Obj
End Sub 展开
Option Explicit Private ObjOldWidth As Long Private ObjOldHeight As Long Private ObjOldFont As Single Private Sub Form_Resize() Call ResizeForm(Me) End SubPrivate Sub Form_Load() Call ResizeInit(Me) End Sub
Public Sub ResizeInit(FormName As Form)
Dim Obj As Control
ObjOldWidth = FormName.ScaleWidth ObjOldHeight = FormName.ScaleHeight ObjOldFont = FormName.Font.Size / ObjOldHeight On Error Resume Next For Each Obj In FormName Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " " Next Obj
On Error GoTo 0 End Sub Public Sub ResizeForm(FormName As Form) Dim Pos(4) As Double Dim i As Long, TempPos As Long, StartPos As Long Dim Obj As Control Dim ScaleX As Double, ScaleY As Double
ScaleX = FormName.ScaleWidth / ObjOldWidth ScaleY = FormName.ScaleHeight / ObjOldHeight On Error Resume Next
For Each Obj In FormName StartPos = 1 For i = 0 To 4 TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare) If TempPos > 0 Then Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos) StartPos = TempPos + 1 Else Pos(i) = 0 End If
Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY Obj.Font.Size = ObjOldFont * FormName.ScaleHeight Next i
Next Obj
End Sub 展开
1个回答
2015-07-29
展开全部
这个你要按正常比列,对每一个控件进行位置的重新设置
以COMAND1控件为例,比如原来1000大小时,左边位置在10%位置
在窗口变大或变小时,重新设置这个左边的位置
但这个其实是不方便的,窗体肯定有最小的能显示的大小,你就按这个大小居中最好,否则代码太多,太麻烦。
以COMAND1控件为例,比如原来1000大小时,左边位置在10%位置
在窗口变大或变小时,重新设置这个左边的位置
但这个其实是不方便的,窗体肯定有最小的能显示的大小,你就按这个大小居中最好,否则代码太多,太麻烦。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询