VB中,如何让一个控件和窗体一起变大

2024-11-29 00:12:46
推荐回答(4个)
回答1:

给你个通用的,自己写的。适用于所有带Move方法的控件。
直接粘贴代码即可。
====================
Private Sub Form_Load()
For Each Control In Controls
Control.Tag = Join(Array(Control.Left, Control.Top, Control.Width, Control.Height))
Next
Tag = Join(Array(Width, Height))
End Sub

Private Sub Form_Resize()
Dim sF, sC
sF = Split(Tag)
For Each Control In Controls
sC = Split(Control.Tag)
Control.Move Width / sF(0) * sC(0), Height / sF(1) * sC(1), Width / sF(0) * sC(2), Height / sF(1) * sC(3)
Next
For Each Control In Controls
Control.Tag = Join(Array(Control.Left, Control.Top, Control.Width, Control.Height))
Next
Tag = Join(Array(Width, Height))

End Sub

回答2:

假设你要改变的控件是text1则加入以下代码:
Private Sub Form_Resize()
Text1.Height = Me.Height
Text1.Width = Me.Width
End Sub

回答3:

上面的代码不行,这样text1就变样了,不信自己试试

下面这个我自己试过了,可以用!(里面只用一个text1控件测试,其他的也同样可以实现

Dim hs
Dim vs
Dim width1
Dim left1
Dim top1
Dim height1
Private Sub form_load()
hs = Form1.Height
vs = Form1.Width
With Text1
width1 = .Width
left1 = .left
top1 = .top
height1 = .Height
End With
End Sub

Private Sub form_resize()
With Text1
.Width = width1 * Form1.Width / vs
.top = top1 * Form1.Height / hs
.left = left1 * Form1.Width / vs
.Height = height1 * Form1.Height / hs
End With
End Sub

回答4:

呵呵,这个相关的问题刚刚回答过:

http://zhidao.baidu.com/question/75778196.html?test=2_2