| 首页 | 新闻 | 网页 | 设计 | 色彩 | 原创 | 视觉 | 素材 | 动漫 | 酷站 | 策划 | 文案 | 访谈 | 运营 | 编程 | 数据库 | 服务器 | 下载 | 图库 | 
您的位置: 幽幽天空 > 网页 > 编程开发 > VB教程 > 文章正文 用户登录
Geesee广告计划详
5GBFreephp空间
无限网络提供50M 
苏能科技100M/FTP
悠博科技50M/FTP/
华云网络30M/FTP/
RealTracker提供免
Sharea免费3G媒体
Flash Remoting -
ASP+FLASH+ACCESS

Resize所有控件           

Resize所有控件

作者:佚名 来源:csdn 作者: shuwork 更新:2006-8-25 21:05:35 错误报告 我要投稿
Option Explicit
' if True, also fonts are resized
Public ResizeFont As Boolean
' if True, form's height/width ratio is preserved
Public KeepRatio As Boolean
Private Type TcontrolInfo
ctrl As Control
Left As Single
Top As Single
Width As Single
Height As Single
FontSize As Single
End Type
' this array holds the original position
' and size of all controls on parent form
Dim Controls() As TcontrolInfo
' a reference to the parent form
Private WithEvents ParentForm As Form
' parent form's size at load time
Private ParentWidth As Single
Private ParentHeight As Single
' ratio of original height/width
Private HeightWidthRatio As Single
Private Sub ParentForm_Load()
' the ParentWidth variable works as a flag
ParentWidth = 0
' save original ratio
HeightWidthRatio = ParentForm.Height / ParentForm.Width
End Sub
Private Sub UserControl_ReadProperties (PropBag As PropertyBag)
ResizeFont = PropBag.ReadProperty("ResizeFont", _
False)
KeepRatio = PropBag.ReadProperty("KeepRatio", _
False)
If Ambient.UserMode = False Then Exit Sub
' store a reference to the parent form and
' start receiving events
Set ParentForm = Parent
End Sub
Private Sub UserControl_WriteProperties (PropBag As PropertyBag)
PropBag.WriteProperty "ResizeFont", ResizeFont, _
False
PropBag.WriteProperty "KeepRatio", KeepRatio, _
False
End Sub
Private Sub UserControl_Resize()
' refuse to resize
Image1.Move 0, 0
UserControl.Width = Image1.Width
UserControl.Height = Image1.Height
End Sub
' trap the parent form's Resize event
' this include the very first resize event
' that occurs soon after form's load
Private Sub ParentForm_Resize()
If ParentWidth = 0 Then Rebuild
Else
   Refresh
End If
End Sub
' save size and position of all controls on parent form
' you should manually invoke this method each time you
' add a new control to the form
' (through Load method of a control array)
Sub Rebuild()
' rebuild the internal table
Dim i As Integer, ctrl As Control
' this is necessary for controls that don't support
' all properties (e.g. Timer controls)
On Error Resume Next
If Ambient.UserMode = False Then Exit Sub
' save a reference to the parent form
' and its initial size
Set ParentForm = UserControl.Parent
ParentWidth = ParentForm.ScaleWidth
ParentHeight = ParentForm.ScaleHeight
' read the position of all controls on the parent form
ReDim Controls(ParentForm.Controls.Count - 1) _
As TcontrolInfo
For i = 0 To ParentForm.Controls.Count ?1
Set ctrl = ParentForm.Controls(i)
With Controls(i)
Set .ctrl = ctrl
.Left = ctrl.Left
.Top = ctrl.Top
.Width = ctrl.Width
.Height = ctrl.Height
.FontSize = ctrl.Font.Size
End With
Next
End Sub
' update size and position of controls on parent form
Sub Refresh()
Dim i As Integer, ctrl As Control
Dim widthFactor As Single, heightFactor As Single
Dim minFactor As Single
' inhibits recursive calls if KeepRatio = True
Static executing As Boolean
If executing Then Exit Sub
If Ambient.UserMode = False Then Exit Sub
If KeepRatio Then
   executing = True
   ' we must keep original ratio
   ParentForm.Height = HeightWidthRatio * _
ParentForm.Width
   executing = False
End If
' this is necessary for controls that don't support
' all properties (e.g. Timer controls)
On Error Resume Next
widthFactor = ParentForm.ScaleWidth / ParentWidth
heightFactor = ParentForm.ScaleHeight / ParentHeight
' take the lesser of the two
If widthFactor < heightFactor Then
   minFactor = widthFactor
Else
   minFactor = heightFactor
End If
' this is a regular resize
For i = 0 To UBound(Controls)
   With Controls(i)
' the change of font must occur *before* the
' resizing to account for companion scrollbar
' of listbox and other similar controls
If ResizeFont Then
.ctrl.Font.Size = .FontSize * minFactor
End If
' move and resize the controls - we can't use a
' Move method because some controls do not
' support the change of all the four properties
' (eg. Height with comboboxes)
.ctrl.Left = .Left * widthFactor
.ctrl.Top = .Top * heightFactor
.ctrl.Width = .Width * widthFactor
.ctrl.Height = .Height * heightFactor
   End With
Next
End Sub
文章录入:skyuu    责任编辑:skyuu 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    发表评论:
    姓名:  评 分: 1分 2分 3分 4分 5分
     
  • 严禁发表危害国家安全、政治、黄色淫秽等内容的评论。
  • 用户需对自己在使用幽幽天空服务过程中的行为承担法律责任。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表机友个人观点,与本网站立场无关。