I'm trying to make my form resize itself in a stretchable type way... the code is working (converted from vb6), however in VB 2005 it is really slow to move the objects. My form has about 100 objects and it is taking approx 4 seconds to move all the controls to where they need to be.
Any way to speed this up?
p.s. I've been using vb for about 5 days, so I'm pretty ignorant.
-george
Code:Public Class Form1 Private m_ControlPositions() As ControlPositionType Private m_FormWid As Single Private m_FormHgt As Single Private Sub SaveSizes() Dim i As Integer Dim ctl As Control ' Save the controls' positions and sizes. ReDim m_ControlPositions(0 To Controls.Count) i = 0 For Each ctl In Controls With m_ControlPositions(i) .Left = ctl.Left .Top = ctl.Top .Width = ctl.Width .Height = ctl.Height On Error Resume Next .FontSize = ctl.Font.Size .daFont = ctl.Font.Style On Error GoTo 0 End With i = i + 1 Next ctl ' Save the form's size. m_FormWid = Me.Width m_FormHgt = Me.Height End Sub ' Arrange the controls for the new size. Private Sub ResizeControls() Dim i As Integer Dim ctl As Control Dim x_scale As Single Dim y_scale As Single Dim font_scale As Single Dim oldfontsize As Single ' Get the form's current scale factors. x_scale = Me.Width / m_FormWid y_scale = Me.Height / m_FormHgt font_scale = (y_scale + x_scale / 2) ' Reposition the controls. i = 0 For Each ctl In Controls With m_ControlPositions(i) If ctl.Name <> "MenuStrip1" Then oldfontsize = .FontSize ctl.Left = x_scale * .Left ctl.Top = y_scale * .Top ctl.Width = x_scale * .Width ctl.Height = y_scale * .Height On Error Resume Next ctl.Font = New Font(ctl.Font.Name, oldfontsize * font_scale) Else End If On Error GoTo 0 End With i = i + 1 Next ctl ' Save the form's size. m_FormWid = Me.Width m_FormHgt = Me.Height End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SaveSizes() Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize ResizeControls() End Sub SaveSizes()




Reply With Quote