VB6 仿.netWinfrom控件 Anchor属性类
vb6中控件没有anchor与dock属性,窗体变大后原来要在resize中调整控件的move属性,否则就面目全非了.网上找到一些调整控件大小的代码,发现并不太适合自己,于是按照思路自己做了一个类似anchor属性的类模块。
代码如下:
Option Explicit
'设置控件Left,Top,Height,Width 类似Anchor属性 '控件大小与位置
Private Type cP
Wp As Single
Hp As Single
Tp As Single
Lp As Single
End Type Private ccp() As cP
Private iCIndex As Integer '控件的index
Private colControl As New Collection
Private frmOldWidth As Single '记录下原始窗口值宽与高
Private frmOldHeight As Single
Private lFrom As Form Public Sub InitControlSize(strCName As String)
'存控件初始位置
colControl.Add iCIndex, strCName ccp(iCIndex).Lp = lFrom.Controls(strCName).Left
ccp(iCIndex).Tp = lFrom.Controls(strCName).Top
ccp(iCIndex).Hp = lFrom.Controls(strCName).Height
ccp(iCIndex).Wp = lFrom.Controls(strCName).Width iCIndex = iCIndex +
End Sub
Public Sub InitFromAllControl()
'把所有控件初始位置大小都保存
If lFrom Is Nothing Then Exit Sub
If iCIndex <> Then Exit Sub Dim myControl As Control
For Each myControl In lFrom.Controls
colControl.Add iCIndex, myControl.Name
ccp(iCIndex).Lp = myControl.Left
ccp(iCIndex).Tp = myControl.Top
ccp(iCIndex).Hp = myControl.Height
ccp(iCIndex).Wp = myControl.Width
iCIndex = iCIndex +
Next
End Sub Public Sub ControlAnchor(strCName As String, _
Optional bLeft As Boolean = False, _
Optional bTop As Boolean = False, _
Optional bHeight As Boolean = False, _
Optional bWidth As Boolean = False)
On Error Resume Next
Dim fHorizontal As Single
Dim fVertical As Single
Dim index As Integer fHorizontal = lFrom.ScaleWidth - frmOldWidth '横坐标 对应 left、width属性
fVertical = lFrom.ScaleHeight - frmOldHeight '纵坐标 对应 Top、Height属性
index = colControl.Item(strCName) '从集合里取得控件的index If bLeft Then lFrom.Controls(strCName).Left = fHorizontal + ccp(index).Lp
If bTop Then lFrom.Controls(strCName).Top = fVertical + ccp(index).Tp
If bHeight Then lFrom.Controls(strCName).Height = fVertical + ccp(index).Hp
If bWidth Then lFrom.Controls(strCName).Width = fHorizontal + ccp(index).Wp End Sub
Public Property Set setFrom(ByVal sValue As Form)
Set lFrom = sValue
frmOldWidth = lFrom.ScaleWidth
frmOldHeight = lFrom.ScaleHeight
ReDim ccp( To lFrom.Controls.Count)
End Property Private Sub Class_Initialize()
iCIndex =
End Sub Private Sub Class_Terminate()
Set lFrom = Nothing
End Sub
调用方法:
Option Explicit
Dim myAnchor As New clsAnchor Private Sub Form_Load()
Set myAnchor.setFrom = Me
myAnchor.InitFromAllControl
End Sub Private Sub Form_Resize()
myAnchor.ControlAnchor "gridOrder", , , True, True
myAnchor.ControlAnchor "Frame2", , , , True
End Sub
效果图:


Collection集合效率不高,可以换成哈希表。
VB6 仿.netWinfrom控件 Anchor属性类的更多相关文章
- 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性
[源码下载] 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件 ...
- c# 控件的基类——Control
控件的基类用于Windows窗体应用的控件都派生自Control类,并继承了许多通用成员,这些成员都是平时使用控件的过程中最常用的. Name:控件实例的名字,通常通过“属性”窗口设置,控件实例名称变 ...
- C#控件事件属性大全
C#控件及常用设计整 1.窗体... 1 2.Label 控件... 3 3.TextBox 控件... 4 4.RichTextBox控件... 5 5.NumericUpDown 控件... 7 ...
- C#常用控件的属性以及方法(转载)
-----以前看别人的,保存了下来,但是忘了源处,望见谅. C#常用控件属性及方法介绍 目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文本框)控件 4.RichText ...
- C#常用控件和属性
目录1.窗体(Form)2.Label (标签)控件3.TextBox(文本框)控件4.RichTextBox控件5.NumericUpDown控件6.Button(按钮)控件7.GroupBox(分 ...
- 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox
[源码下载] 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(选择类) Sel ...
- 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton
[源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...
- 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox
[源码下载] 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) T ...
- 背水一战 Windows 10 (27) - 控件(文本类): TextBlock
[源码下载] 背水一战 Windows 10 (27) - 控件(文本类): TextBlock 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) TextBlock 示例 ...
随机推荐
- 思考 ”前端开发人员都在关注的 GitHub 资源“
点这里 原文: 资源 免费的计算机编程类中文书籍 免费编程书籍 计算机科学论文 codeparkshare Python初学者书籍.视频.资料.社区推荐 Python资料汇总 app应用推荐 码农周刊 ...
- POJ 1450
#include <iostream> using namespace std; int main() { //freopen("acm.acm","r&qu ...
- Difference Between Initialization and Assignment in C++
Initialization happens when a variable is given a value at the moment it is created. Assignment obli ...
- hdu 4389 X mod f(x) 数位DP
思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...
- Node 出现 uncaughtException 之后的优雅退出方案
Node 的异步特性是它最大的魅力,但是在带来便利的同时也带来了不少麻烦和坑,错误捕获就是一个.由于 Node 的异步特性,导致我们无法使用 try/catch 来捕获回调函数中的异常,例如: try ...
- JAVA Map集合类简介
了解最常用的集合类型之一 Map 的基础知识以及如何针对您应用程序特有的数据优化 Map. 本文相关下载: · Jack 的 HashMap 测试· Oracle JDeveloper 10g jav ...
- hdu2022(water~~)海选女主角
http://acm.hdu.edu.cn/showproblem.php?pid=2022 二B了,没读题直接错了两次....郁闷 #include <iostream> #includ ...
- 当C++学到第20天的时候我崩溃了(找回刚开始的激情)
首先声明,我是个使用多语言(ASM/C/C++/Java/Perl)的人,主要使用C++和Java所以我认为我的意见还算中肯.那些否定C++的人,你们是否了解————Borland鼓吹Delphi如何 ...
- DB2操作流程
DB2如何创建表空间 如何创建数据库 如何创建缓冲池标签: db2数据库system脚本linuxwindows2012-06-13 19:16 8411人阅读 评论(0) 收藏 举报 版权声明:本文 ...
- ARP:地址解析协议
ARP是地址解析协议,简单语言解释一下工作原理.1:首先,每个主机都会在自己的ARP缓冲区中建立一个ARP列表,以表示IP地址和MAC地址之间的对应关系.2:当源主机要发送数据时,首先检查ARP列表中 ...