这是"海牛猪猪"给我写的,你去参考一下吧! 第一部分代码 Option ExplicitPrivate Sub Form_Load() Dim lFormWidth As Long Dim lFormHeight As Long
lFormWidth = Me.ScaleWidth lFormHeight = Me.ScaleHeight '第二步分 Me.Command1.Tag = Me.Command1.Width / lFormWidth & "|" & Me.Command1.Height / lFormHeight Me.Command3.Tag = Me.Command1.Width / lFormWidth & "|" & Me.Command1.Height / lFormHeight Me.Command4.Tag = Me.Command1.Width / lFormWidth & "|" & Me.Command1.Height / lFormHeight End SubPrivate Sub Form_Resize() If Me.WindowState <> 1 Then Call ResizeControls End Sub Private Sub ResizeControls() Dim objC As Object Dim strarrK() As String Dim lW As Long, lH As Long lW = Me.ScaleWidth lH = Me.ScaleHeight For Each objC In Me.Controls If TypeOf objC Is CommandButton Then If Len(objC.Tag) <> 0 Then strarrK = Split(CStr(objC.Tag), "|") objC.Width = lW * Val(strarrK(0)) objC.Height = lH * Val(strarrK(1)) End If Next objC End Sub '添加四个CommandButton
第一部分代码
Option ExplicitPrivate Sub Form_Load()
Dim lFormWidth As Long
Dim lFormHeight As Long
lFormWidth = Me.ScaleWidth
lFormHeight = Me.ScaleHeight '第二步分
Me.Command1.Tag = Me.Command1.Width / lFormWidth & "|" & Me.Command1.Height / lFormHeight
Me.Command3.Tag = Me.Command1.Width / lFormWidth & "|" & Me.Command1.Height / lFormHeight
Me.Command4.Tag = Me.Command1.Width / lFormWidth & "|" & Me.Command1.Height / lFormHeight
End SubPrivate Sub Form_Resize()
If Me.WindowState <> 1 Then
Call ResizeControls
End Sub
Private Sub ResizeControls()
Dim objC As Object
Dim strarrK() As String
Dim lW As Long, lH As Long
lW = Me.ScaleWidth
lH = Me.ScaleHeight
For Each objC In Me.Controls
If TypeOf objC Is CommandButton Then
If Len(objC.Tag) <> 0 Then
strarrK = Split(CStr(objC.Tag), "|")
objC.Width = lW * Val(strarrK(0))
objC.Height = lH * Val(strarrK(1))
End If
Next objC
End Sub
'添加四个CommandButton
充分利用控件的tag属性希望楼主不要期望大家提供给你直接可以执行的代码,自己的程序必须要自己写,
我们在这里讨论的关键是思路。
控件.height= Me.ScaleHeight
txtNote.Move 20, 20, Me.Width - 100, Me.Height - 200
End Sub数字就是边距了,自己调一下就OK了
我刚试了一下,效果是有一点,但总是不够完美!
vbanddelphi(一枝梨花) ???有没有更好的意见???