Advertisement
Java_Volume1 VB function enhancement #87536

Anchor Class

Anchors, makes controls size along with the form. I wanted to use anchors in VB and make this class in order to save some time. I hope you'll find it usefull.

AI

สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ซอร์สโค้ด
original-source
'-----------------------------------------------------
'         Costum Anchor Class
'            for VB
'        by Ferry "FTPlus" Timers
'-----------------------------------------------------
'
' Usage: (in 4 steps)
'
' 1. Declare as a new class
'
' example: Dim ancTextbox1 as new Anchor
'
' 2. Initalize the anchor and hook the control to the class (init before movement)
'  (it remembers the margins)
'
' example: anc.Textbox1.Init Textbox1
'
' 3. Set the anchor points (Left, Top, Right, Bottom)
'
' example: ancTextbox1.SetAnchors True, False, True, True
'
' 4. And Finaly lets justify the sizes (best to place in Form_Resize)
'
' example: ancTextbox1.Update
'
'-----------------------------------------------------
'           Have Fun
'-----------------------------------------------------
Private Type tAnchor
 Left As Boolean
 Top As Boolean
 Right As Boolean
 Bottom As Boolean
End Type
Public Container As Object
Private Anchors As tAnchor
Private marginLeft As Integer
Private marginTop As Integer
Private marginRight As Integer
Private marginBottom As Integer
Public Sub Init(ByRef Obj As Object)
Set Container = Obj
With Container
 marginLeft = .Left
 marginTop = .Top
 marginRight = .Container.Width - .Left - .Width
 marginBottom = .Container.Height - .Top - .Height
End With
End Sub
Public Sub SetAnchors(Left As Boolean, Top As Boolean, Right As Boolean, Bottom As Boolean)
With Anchors
 .Left = Left
 .Top = Top
 .Right = Right
 .Bottom = Bottom
End With
End Sub
Public Sub Update()
Dim I As Integer
If Anchors.Left Then
 Container.Left = marginLeft
 If Anchors.Right Then
  I = Container.Container.Width - marginLeft - marginRight
  If I > 0 Then Container.Width = I
 End If
ElseIf Anchors.Right Then
 I = Container.Container.Width - Container.Width - marginRight
 If I > 0 Then Container.Left = I
End If
If Anchors.Top Then
 Container.Top = marginTop
 If Anchors.Bottom Then
  I = Container.Container.Height - marginTop - marginBottom
  If I > 0 Then Container.Height = I
 End If
ElseIf Anchors.Bottom Then
 I = Container.Container.Height - Container.Height - marginBottom
 If I > 0 Then Container.Top = I
End If
End Sub
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine