Type cp wp As Single hp As Single tp As Single lp As
Single End
Type (2)定义一个窗体级数组
在窗体模块的声明段写入:
Dim ap() As cp (3)定义一个通用过程
Sub ai() Dim i As Integer For i=0 To Controls.Count-1 With
ap(i) .wp=Controls(i).Width/Form1.ScaleWidth .hp=Controls(i).Height/Form1.ScaeHeight .lp=Controls(i).Left/Form1.DcaleWidth .tp=COntrols(i),Top/Form1.ScaleHeight End
With Next i End
Sub (4)在窗体的Load事件过程中写入代码:
Private Sub Form_Load() ReDim ap (0 To
Controls.Count-1) ai End
Sub (5)在窗体的Resize事件过程中写入代码:
Private Sub Form_Resize() Dim i As Integer For i=0 To
Controls.Count-1 以下三行需在一行内写完
Controls(i).Move ap(i).1p * Form1.ScaleWidth, ap(i).tp *
Form1.ScaleHeight,ap(i).WP*Form1.ScaleWidth, ap(i).hp *
Form1.ScaleHeight Next i End
Sub 不难看出,上面的代码具有普遍意义:即对于任何VB程序,只要将上面给出的代码按照要求写入程序中,则无论该VB程序的一个窗体中具有多少控件,均能使窗体内的控件自适应于窗体尺寸缩放,从而解决了控件与窗体在尺寸和位置两方面的比例失调问题。
没有相关教程