0 Replies - 289 Views - Last Post: 15 October 2013 - 12:59 PM Rate Topic: -----

#1 vegetax007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-October 13

drag resize and maximize button resize

Posted 15 October 2013 - 12:59 PM

Hello everyone,
I have to admit I am losing my mind. I am a newbie to using visual basic 2010 and coding with the such. I am trying to get my project off to the right start by making my form scale everything when it is resized. Currently with my code I had found a way to scale and resize everything with when using the mouse to drag and resize (see code below). When I click and drag things they will grow and shrink accordingly. But I run into my problems when I try and have the form scale when I hit the windows form maximize and restore button. I cannot figure out how to make both work. With the code below the Xratio and Yratio variable are set on form load with a getting the original screen height and width divide by a set resolution of 800 X 600. If anyone can point me in the right direction or what command I need to use I will be very grateful.



below is a routine I have for finding every control on the form.
 Function GetAllControls(ByVal container As Control) As Control()
        Dim al As New ArrayList
        Dim ctl As Control
        For Each ctl In container.Controls
            GetControlsWithChildren(ctl, al)
        Next
        Return al.ToArray(GetType(Control))
    End Function

    Sub GetControlsWithChildren(ByVal container As Control, ByVal al As ArrayList)
        ' add this control to the ArrayList
        al.Add(container)
        ' add all its child controls, by calling this routine recursively
        Dim ctl As Control

        For Each ctl In container.Controls
            'A TabPage is a Panel; SplitContainer is a Panel
            GetControlsWithChildren(ctl, al)
        Next

    End Sub

    Private Sub GetTheChildren()
        'Gets the controls inside containes like panels or tabcontrols
        'For Each ctl As Control In GetAllControls(Me.Parent)
        For Each ctl As Control In GetAllControls(Me)
            If ctl.Parent IsNot Me Then
                If TypeOf ctl.Parent Is TabPage Then
                    If ctl.Name = "" Then
                        CtlArray.Add(ctl)
                    Else
                        CtlArray.Add(ctl)
                    End If
                Else
                    If Not TypeOf (ctl) Is TabPage Then
                        If ctl.Name = "" Then
                            CtlArray.Add(ctl)
                        Else
                            CtlArray.Add(ctl)
                        End If
                    End If
                End If
            End If
        Next
    End Sub 


once I have everything, I use this code below to then resize everything.

 Private Sub ResizeThem()
        Dim i As Integer
        For i = 0 To CtlArray.Count - 1
            If TypeOf CtlArray.Item(i) Is MenuStrip Then
            Else
                If TypeOf CtlArray.Item(i) Is Panel And CtlArray.Item(i).parent IsNot Me Then
                    'SplitPanel for instance
                Else
                    CtlArray.Item(i).autosize = False
                    CtlArray.Item(i).dock = 0
                    CtlArray.Item(i).width = CtlArray.Item(i).width * Xratio
                    CtlArray.Item(i).left = CtlArray.Item(i).left * Xratio
                    CtlArray.Item(i).height = CtlArray.Item(i).height * Yratio
                    CtlArray.Item(i).top = CtlArray.Item(i).top * Yratio
                End If
            End If
        Next
    End Sub


Then to activate the resize with the dragging of the mouse I use the following code.

 Private Sub Form1_ResizeBegin(sender As Object, e As System.EventArgs) Handles Me.ResizeBegin
        BeforeHieght = Me.Height
        BeforeWidth = Me.Width
    End Sub

    Private Sub Form1_ResizeEnd(sender As Object, e As System.EventArgs) Handles Me.ResizeEnd
        AfterHieght = Me.Height
        AfterWidth = Me.Width

        Dim i As Integer
        For i = 0 To CtlArray.Count - 1
            If TypeOf CtlArray.Item(i) Is MenuStrip Then
            Else
                If TypeOf CtlArray.Item(i) Is Panel And CtlArray.Item(i).parent IsNot Me Then
                    'SplitPanel for instance
                Else
                    CtlArray.Item(i).autosize = False
                    CtlArray.Item(i).dock = 0
                    CtlArray.Item(i).width = CtlArray.Item(i).width * (AfterWidth / BeforeWidth)
                    CtlArray.Item(i).left = CtlArray.Item(i).left * (AfterWidth / BeforeWidth)
                    CtlArray.Item(i).height = CtlArray.Item(i).height * (AfterHieght / BeforeHieght)
                    CtlArray.Item(i).top = CtlArray.Item(i).top * (AfterHieght / BeforeHieght)

                End If
            End If
        Next
    End Sub


Is This A Good Question/Topic? 0
  • +

Page 1 of 1