原创技术分享: ControlsAnchor.cls V1.1 本帖最后由 bcrun 于 2013-07-17 16:07:10 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 测试窗体部分:frmMain.frmVERSION 5.00Begin VB.Form frmMain Caption = "frmMain" ClientHeight = 4935 ClientLeft = 120 ClientTop = 450 ClientWidth = 7875 LinkTopic = "Form2" ScaleHeight = 4935 ScaleWidth = 7875 StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = "反复打开关闭Form1测试" Height = 855 Left = 1440 TabIndex = 0 ToolTipText = "反复打开关闭Form1测试" Top = 1320 Width = 1575 EndEndAttribute VB_Name = "frmMain"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitPrivate Sub Command1_Click() Form1.Show vbModalEnd SubForm1.frmVERSION 5.00Begin VB.Form Form1 Caption = "Form1" ClientHeight = 4050 ClientLeft = 120 ClientTop = 450 ClientWidth = 7365 BeginProperty Font Name = "Tahoma" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty LinkTopic = "Form1" ScaleHeight = 4050 ScaleWidth = 7365 ShowInTaskbar = 0 'False StartUpPosition = 3 '窗口缺省 Begin VB.TextBox Text1 Height = 495 Left = 240 TabIndex = 5 Text = "Text1" Top = 360 Width = 1215 End Begin VB.CommandButton cmdOk Caption = "Ok" Height = 360 Left = 6120 TabIndex = 4 Top = 2760 Width = 990 End Begin VB.CommandButton cmdAbout Caption = "About" Height = 360 Left = 6000 TabIndex = 3 Top = 360 Width = 990 End Begin VB.PictureBox Picture1 Height = 2535 Left = 1560 ScaleHeight = 2475 ScaleWidth = 4395 TabIndex = 0 TabStop = 0 'False Top = 1080 Width = 4455 Begin VB.CommandButton cmdCommand1 Caption = "Command1" Height = 360 Left = 3240 TabIndex = 2 Top = 1800 Width = 990 End Begin VB.TextBox txtText1 Height = 615 Left = 720 MultiLine = -1 'True TabIndex = 1 Text = "Form1.frx":0000 Top = 480 Width = 1215 End EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitPrivate m_Sizer As New CControlsAnchorPrivate m_PicBoxSizer As New CControlsAnchorPrivate Sub Form_Load() '下一句体现了VB6 forms的特点,Controls集合里连PictureBox容器内的控件都算上了,而PictureBox '本身并没有Controls,可见在项目代码移植时,这会引起不必要的麻烦. Caption = Me.Controls.Count Call m_Sizer.Init(Me) Call m_Sizer.AddControl("cmdOk", cmdOk, AnchorStyles.Bottom + AnchorStyles.Right) Call m_Sizer.AddControl("cmdAbout", cmdAbout, AnchorStyles.Top + AnchorStyles.Right) Call m_Sizer.AddControl("Picture1", Picture1, AnchorStyles.All) Call m_Sizer.AddControl("Text1", Text1, AnchorStyles.Left) Call m_PicBoxSizer.Init(Me, Picture1) Call m_PicBoxSizer.AddControl("cmdCommand1", cmdCommand1, AnchorStyles.Bottom + AnchorStyles.Right) Debug.Print txtText1.Parent.NameEnd Sub 后面两个窗体的代码直接复制出去存为相应的frm文件,这个是演示效果的。 我这个基本上就是按.net里WinForms那个Anchor的效果来写的。你说的那个是不是类似Dock的(即vb6 form里的Align? 后面两个窗体的代码直接复制出去存为相应的frm文件,这个是演示效果的。现在真看不懂,能指点一下吗?我把它拷出来后运行后就是"ok""about""command"和"txt1"拖动窗口后没有规律地移动,没有见到说是按比例定位也没有见到是按比例缩放?谢谢了. vb6编个小事例 怎样连接sql数据苦 新手请达人指点. VB创建word的表格消耗资源的问题 请问一个sql语句写法 请教:这样的一个函数怎么做成一个dll?做成DLL之后,在一个新建成的工程中怎么调用? vb如何调用sql server的存储过程(我是嗷嗷待哺的小鸟) VB的List的用法的两个小问题,谢谢! VB Controls.Add无法用它新建控件的事务 請教各位如何連接dbf數據庫? 我在家里作的vb为什么在学校里打不开? 用vb创建大数组,可是系统越用越慢,如何用别的方法替换。 求帮助:滚动条有时出现:实时错误 380无效的属性值 数据更新,求思路
frmMain.frm
VERSION 5.00
Begin VB.Form frmMain
Caption = "frmMain"
ClientHeight = 4935
ClientLeft = 120
ClientTop = 450
ClientWidth = 7875
LinkTopic = "Form2"
ScaleHeight = 4935
ScaleWidth = 7875
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "反复打开关闭Form1测试"
Height = 855
Left = 1440
TabIndex = 0
ToolTipText = "反复打开关闭Form1测试"
Top = 1320
Width = 1575
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitPrivate Sub Command1_Click()
Form1.Show vbModal
End Sub
Form1.frm
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4050
ClientLeft = 120
ClientTop = 450
ClientWidth = 7365
BeginProperty Font
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 4050
ScaleWidth = 7365
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 495
Left = 240
TabIndex = 5
Text = "Text1"
Top = 360
Width = 1215
End
Begin VB.CommandButton cmdOk
Caption = "Ok"
Height = 360
Left = 6120
TabIndex = 4
Top = 2760
Width = 990
End
Begin VB.CommandButton cmdAbout
Caption = "About"
Height = 360
Left = 6000
TabIndex = 3
Top = 360
Width = 990
End
Begin VB.PictureBox Picture1
Height = 2535
Left = 1560
ScaleHeight = 2475
ScaleWidth = 4395
TabIndex = 0
TabStop = 0 'False
Top = 1080
Width = 4455
Begin VB.CommandButton cmdCommand1
Caption = "Command1"
Height = 360
Left = 3240
TabIndex = 2
Top = 1800
Width = 990
End
Begin VB.TextBox txtText1
Height = 615
Left = 720
MultiLine = -1 'True
TabIndex = 1
Text = "Form1.frx":0000
Top = 480
Width = 1215
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private m_Sizer As New CControlsAnchor
Private m_PicBoxSizer As New CControlsAnchorPrivate Sub Form_Load()
'下一句体现了VB6 forms的特点,Controls集合里连PictureBox容器内的控件都算上了,而PictureBox
'本身并没有Controls,可见在项目代码移植时,这会引起不必要的麻烦.
Caption = Me.Controls.Count
Call m_Sizer.Init(Me)
Call m_Sizer.AddControl("cmdOk", cmdOk, AnchorStyles.Bottom + AnchorStyles.Right)
Call m_Sizer.AddControl("cmdAbout", cmdAbout, AnchorStyles.Top + AnchorStyles.Right)
Call m_Sizer.AddControl("Picture1", Picture1, AnchorStyles.All)
Call m_Sizer.AddControl("Text1", Text1, AnchorStyles.Left)
Call m_PicBoxSizer.Init(Me, Picture1)
Call m_PicBoxSizer.AddControl("cmdCommand1", cmdCommand1, AnchorStyles.Bottom + AnchorStyles.Right)
Debug.Print txtText1.Parent.Name
End Sub
后面两个窗体的代码直接复制出去存为相应的frm文件,这个是演示效果的。
我这个基本上就是按.net里WinForms那个Anchor的效果来写的。你说的那个是不是类似Dock的(即vb6 form里的Align?
后面两个窗体的代码直接复制出去存为相应的frm文件,这个是演示效果的。现在真看不懂,能指点一下吗?我把它拷出来后运行后就是"ok""about""command"和"txt1"拖动窗口后没有规律地移动,没有见到说是按比例定位也没有见到是按比例缩放?谢谢了.