让窗体的控件自动跟随尺寸变化而自适应位置:
支持最小固定尺寸:
用法示例:(来源于 newxing)
VERSION 5.00
Begin VB.Form frm_main
Caption = "窗体控件自动缩放演示 Ver1.0 "
ClientHeight = 5685
ClientLeft = 60
ClientTop = 345
ClientWidth = 8865
Icon = "frm_main.frx":0000
LinkTopic = "Form1"
ScaleHeight = 5685
ScaleWidth = 8865
StartUpPosition = 3 '窗口缺省
Begin VB.ComboBox Combo1
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 330
Left = 3540
TabIndex = 12
Tag = "MOVEALL"
Text = "ComboBox 示例"
Top = 5280
Width = 2250
End
Begin VB.CommandButton cmd_more
Caption = "更多示例"
Height = 360
Left = 7440
TabIndex = 11
Tag = "MOVEALL"
Top = 5280
Width = 1395
End
Begin VB.TextBox Text3
Height = 345
Left = 1500
TabIndex = 10
Tag = "STRETCHHMOVEV"
Text = "TextBoxx 示例"
Top = 5265
Width = 1995
End
Begin VB.ListBox List1
Height = 3180
IntegralHeight = 0 'False
ItemData = "frm_main.frx":08CA
Left = 6840
List = "frm_main.frx":08D1
TabIndex = 9
Tag = "STRETCHVMOVEH"
Top = 2070
Width = 1995
End
Begin VB.CommandButton cmd_example
Caption = "MOVEV"
Height = 360
Index = 3
Left = 60
TabIndex = 8
Tag = "MOVEV"
Top = 5250
Width = 1395
End
Begin VB.CommandButton cmd_example
Caption = "MOVEALL"
Height = 360
Index = 2
Left = 5850
TabIndex = 7
Tag = "MOVEALL"
Top = 5265
Width = 1395
End
Begin VB.TextBox Text2
Height = 3180
Left = 2100
TabIndex = 6
Tag = "STRETCHALL"
Text = "STRETCHALL"
Top = 2070
Width = 4695
End
Begin VB.CommandButton cmd_example
Caption = "MOVEH"
Height = 330
Index = 1
Left = 7440
TabIndex = 5
Tag = "MOVEH"
Top = 1680
Width = 1395
End
Begin VB.TextBox Text1
Height = 330
Left = 1500
TabIndex = 4
Tag = "STRETCHH"
Text = "TextBoxx 示例"
Top = 1680
Width = 5895
End
Begin VB.ListBox lst_example
Height = 3165
IntegralHeight = 0 'False
ItemData = "frm_main.frx":08E2
Left = 60
List = "frm_main.frx":08E9
TabIndex = 3
Tag = "STRETCHV"
Top = 2070
Width = 1995
End
Begin VB.CommandButton cmd_example
Caption = "无标志"
Height = 345
Index = 0
Left = 60
TabIndex = 2
Top = 1680
Width = 1395
End
Begin VB.Frame fra_information
Caption = "提示系信息"
Height = 1575
Left = 60
TabIndex = 0
Tag = "STRETCHH"
Top = 60
Width = 8775
Begin VB.Image img_icon
Height = 480
Left = 420
Picture = "frm_main.frx":08FA
Top = 540
Width = 480
End
Begin VB.Label lbl_info1
Alignment = 2 'Center
Caption = $"frm_main.frx":11C4
Height = 615
Left = 1320
TabIndex = 1
Tag = "STRETCHH"
Top = 480
Width = 7275
End
End
End
Attribute VB_Name = "frm_main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Download by http://www.NewXing.com
Option Explicit
'----------------------------------------------------------
'名称 : AUTOSIZE
'作者 : NICK PATEMAN
'EMAIL : np24@blueyonder.co.uk
'----------------------------------------------------------
'***********************************
'私有变量
'***********************************
'------------------------------------------
'窗体对象数据
'------------------------------------------
Dim frm_main_objects() As objectinfo
Dim frm_main_effectobjects() As Object
Private frm_main_noofobjects As Integer
Private frm_main_startwidth As Long
Private frm_main_startheight As Long
'***********************************
'窗体事件
'***********************************
'------------------------------------------
'载入窗体
'------------------------------------------
Private Sub Form_Load()
frm_main_startwidth = Me.width
frm_main_startheight = Me.height
restrictform Me
End Sub
'------------------------------------------
'卸载窗体
'------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
unrestrictform Me
End Sub
'------------------------------------------
'缩放窗体内容
'------------------------------------------
Private Sub Form_Resize()
'以前你可能需要写入很多缩放窗体内控件的代码,现在仅仅需要一句代码即可搞定
'你只要在要缩放的控件的TAG属性值里设置标志,然后使用下面的语句即可
'Autosizeform Me, True
Autosizeform frm_main_objects, frm_main_effectobjects, frm_main_startwidth, frm_main_startheight, frm_main_noofobjects, Me
End Sub
'***********************************
'按钮
'***********************************
'------------------------------------------
'演示其它的示例
'------------------------------------------
Private Sub cmd_more_Click()
frm_test.Show
End Sub
主要模块:(来源作者是老外:
'----------------------------------------------------------
'名称 : AUTOSIZE
'作者 : NICK PATEMAN
'EMAIL : np24@blueyonder.co.uk
'----------------------------------------------------------
只要再自己的项目引用这2个模块,就可以一键调用了,
Views: 232