VB6.0应用程序界面设计探讨

豆豆网   技术应用频道   2006年07月29日    社区交流

本文详细介绍VB6.0应用程序界面设计探讨

  (1)自定义一个数据类型

  在标准模块的声明段写入:

  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程序的一个窗体中具有多少控件,均能使窗体内的控件自适应于窗体尺寸缩放,从而解决了控件与窗体在尺寸和位置两方面的比例失调问题。

作者:务实    责编:豆豆技术应用

正在加载评论...