Hola amigos, .net tiene una funcion, o mejor dicho propiedad, que permite setear a un control del form, que quede "anclado" (anchor) a algun borde del form, esta bueno, porque si anclamos a los 4 bordes, tenemos un resize automatico del control.
Bueno, en vb6 esto siempre lo hice a manopla, pero el otro dia cansado dije... haber si me sale algo un poco mas prolijo, y me salio una clase que permite hacer esto.
Permite elegir a que lado queremos anclar, tal vez solo derecha, o tambien abajo
Para usarlo hay que agregar cada control a dimensionar asi:
Private Sub Form_Load()
Set oResize = New cAnchor
'agregar controles para resize
oResize.AddAnchorCtrl Me.Picture1, , , True, True
oResize.AddAnchorCtrl Me.Picture2, False, True, True, True
oResize.AddAnchorCtrl Me.Command1, False, False, True, True
oResize.AddAnchorCtrl Me.Frame1, True, True, True, False
End Sub
Y en el resize del Form, hay que llamar a ReSizeCtrls:
Private Sub Form_Resize()
oResize.ReSizeCtrls Me
End Sub
Les dejo algunas capturas:



El codigo:
'---------------------------------------------------------------------------------------
' Module : cAnchor
' Author : Waldo
' Date : 27/06/2014
' Purpose : Resize de controles, simulando la propiedad "Anchor" de vb.net
'---------------------------------------------------------------------------------------
Option Explicit
'coleccion de controles para resize
Private colCtrls As Collection
Public Sub AddAnchorCtrl(ByRef oCtrol As Control, _
Optional bAnchorTop As Boolean = True, _
Optional bAnchorLeft As Boolean = True, _
Optional bAnchorBottom As Boolean = False, _
Optional bAnchorRight As Boolean = False)
Dim NewCtrl As cCtrl
Set NewCtrl = New cCtrl
'guardar las propiedades del control actual en la clase
With NewCtrl
Set .ControlRef = oCtrol
.AnchorBottom = bAnchorBottom
.AnchorLeft = bAnchorLeft
.AnchorRight = bAnchorRight
.AnchorTop = bAnchorTop
End With
'agregar este control a la coleccion de controles
colCtrls.Add NewCtrl, oCtrol.Name
Set NewCtrl = Nothing
End Sub
'llamar cada vez que hace resize el form
Public Sub ReSizeCtrls(ByRef oForm As Form)
Dim xCtrol As cCtrl
For Each xCtrol In colCtrls
RePosCtrl xCtrol, oForm
Next
End Sub
Private Sub RePosCtrl(ByRef oCtrl As cCtrl, ByRef oForm As Form)
Dim oContRef As Control
Dim lNewWidth As Long
Dim lNewHeight As Long
Set oContRef = oCtrl.ControlRef
'anclar TOP
If oCtrl.AnchorTop Then
oContRef.Top = oCtrl.Top
Else
oContRef.Top = oForm.Height - oContRef.Height - oCtrl.Bottom
End If
'anclar LEFT
If oCtrl.AnchorLeft Then
oContRef.Left = oCtrl.Left
Else
oContRef.Left = oForm.Width - oContRef.Width - oCtrl.Right
End If
'anclar Right
If oCtrl.AnchorRight Then
lNewWidth = oForm.Width - oContRef.Left - oCtrl.Right
If lNewWidth < 0 Then lNewWidth = 0
oContRef.Width = lNewWidth
End If
'anclar Bottom
If oCtrl.AnchorBottom Then
lNewHeight = oForm.Height - oContRef.Top - oCtrl.Bottom
If lNewHeight < 0 Then lNewHeight = 0
oContRef.Height = lNewHeight
End If
Set oContRef = Nothing
End Sub
Private Sub Class_Initialize()
Set colCtrls = New Collection
End Sub
Private Sub Class_Terminate()
Set colCtrls = Nothing
End Sub
'---------------------------------------------------------------------------------------
' Module : cCtrl
' Author : Waldo
' Date : 27/06/2014
' Purpose : guarda posiciones originales de un control
'---------------------------------------------------------------------------------------
Option Explicit
'propiedades publicas
'definen lado para anclar
Public AnchorTop As Boolean
Public AnchorLeft As Boolean
Public AnchorBottom As Boolean
Public AnchorRight As Boolean
'privadas de las propiedades
Private m_oControlRef As Object 'control origen
Private m_oForm As Form 'form containner
Private m_lLeft As Long 'posiciones de control original
Private m_lTop As Long
Private m_lHeight As Long
Private m_lWidth As Long
Private m_lRightMargin As Long 'margen calculado right
Private m_lBottomMargin As Long 'margen calculado bottom
Public Property Get ControlRef() As Object
Set ControlRef = m_oControlRef
End Property
Public Property Set ControlRef(ByRef oControlRef As Object)
Dim xContainer As Object
Set m_oControlRef = oControlRef
m_lLeft = oControlRef.Left
m_lTop = oControlRef.Top
m_lHeight = oControlRef.Height
m_lWidth = oControlRef.Width
'obtener el contenedor del control
Set xContainer = oControlRef.Container
'calcular margen right y bottom del control orig
m_lRightMargin = xContainer.Width - oControlRef.Width - oControlRef.Left
m_lBottomMargin = xContainer.Height - oControlRef.Height - oControlRef.Top
End Property
Public Property Get Left() As Long
Left = m_lLeft
End Property
Public Property Let Left(ByVal lLeft As Long)
m_lLeft = lLeft
End Property
Public Property Get Top() As Long
Top = m_lTop
End Property
Public Property Let Top(ByVal lTop As Long)
m_lTop = lTop
End Property
Public Property Get Height() As Long
Height = m_lHeight
End Property
Public Property Let Height(ByVal lHeight As Long)
m_lHeight = lHeight
End Property
Public Property Get Width() As Long
Width = m_lWidth
End Property
Public Property Let Width(ByVal lWidth As Long)
m_lWidth = lWidth
End Property
Public Property Get Right() As Long
Right = m_lRightMargin
End Property
Public Property Let Right(ByVal lRight As Long)
m_lRightMargin = lRight
End Property
Public Property Get Bottom() As Long
Bottom = m_lBottomMargin
End Property
Public Property Let Bottom(ByVal lBottom As Long)
m_lBottomMargin = lBottom
End Property
y aca todo el proyecto
http://www.mediafire.com/download/l5d37ybda74cqz9/cAnchor.rar