VB如何使一个image与窗口大小保持比例?

来源:百度知道 编辑:UC知道 时间:2024/06/16 09:27:29
我发布成了一个exe,一打开后,觉得窗口大小不合适,就把窗口拉大了,但是只是窗口变大了,里面的内容没有跟着变大,如何让一个窗口不管拉成什么样子控件也变成什么样子?

以下代码适用于所有带Move方法的控件(当然包括Image)。
============
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

'以下为通用的 代码··试试看吧
Option Explicit
Private FormOldWidth As Long
'保存窗体的原始宽度
Private FormOldHeight As Long
'保存窗体的原始高度

'在调用ResizeForm前先调用本函数
Public Sub ResizeInit(FormName As Form)
Dim Obj As Con