Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CSS
I`ve got a problem with the code re-size the window with the tools
This code works slowly, and marked the piece I want it to work faster than the piece and thank you
Note: The source code is a Class and is being recalled in the two events


The code in class
VB
Public HeightProportions As Double
    Public WidthProportions As Double
    Public TopProportions As Double
    Public LeftProportions As Double


    Public Structure ControlMetrix
        Dim HeightProportions As Double
        Dim WidthProportions As Double
        Dim TopProportions As Double
        Dim LeftProportions As Double

    End Structure
    Public ControlMetrix1() As ControlMetrix

    Public Sub ControlResize(ByRef FormName As System.Windows.Forms.Form)

        On Error Resume Next

        With FormName
            If .WindowState = System.Windows.Forms.FormWindowState.Minimized Then Exit Sub
            TopProportions = .Top
            LeftProportions = .Left
            HeightProportions = .Height
            WidthProportions = .Width


            For a As Integer = 0 To .Controls.Count - 1

                With .Controls(a)
                    .Top = HeightProportions * ControlMetrix1(a).TopProportions
                    .Left = WidthProportions * ControlMetrix1(a).LeftProportions
                    .Height = HeightProportions * ControlMetrix1(a).HeightProportions
                    .Width = WidthProportions * ControlMetrix1(a).WidthProportions
                End With
            Next a

        End With

    End Sub

    Public Sub GetHandleCreated(ByRef FormName As System.Windows.Forms.Form)

        On Error Resume Next

        With FormName

            TopProportions = .Top
            LeftProportions = .Left
            HeightProportions = .Height
            WidthProportions = .Width

            ReDim ControlMetrix1(.Controls.Count() - 1)

            ReDim ControlMetrix1(.Controls.Count - 1)

            For x As Integer = 0 To .Controls.Count - 1

                With .Controls(x)
                    ControlMetrix1(x).TopProportions = (.Top / HeightProportions)
                    ControlMetrix1(x).LeftProportions = (.Left / WidthProportions)
                    ControlMetrix1(x).HeightProportions = (.Height / HeightProportions)
                    ControlMetrix1(x).WidthProportions = (.Width / WidthProportions)
                End With

            Next x

        End With

    End Sub

the event
VB
1:  Private Sub MainForm_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleCreated
        On Error Resume Next

        ResizeMetrix.GetHandleCreated(Me)
    End Sub

2: Private Sub MainForm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        On Error Resume Next

        ResizeMetrix.ControlResize(Me)
    End Sub
Posted

1 solution

Well, if you have many controls, it could work slowly indeed. At least the fact the resize works in principle says that you don't have infinite recursion due to an attempt to change form's size in response to resize, which is already good. :-)

But from the design standpoint, this is (usually) a wrong approach. Normally, you should not handle Resize at all or do very little in response to this event. Instead, you should develop layout which adjusts itself the the form size. The idea is to get rid of any absolute positioning and setting all or most of the Size properties. Instead, you should use a hierarchy of nested panels and the combinations of the properties Dock and Padding.

Please see my past answer with recommendations of the topic:
Zom Out malfunctions when Screen resolution changes[^].

Here you will find a rudimentary code sample:
how to dock button so that it can adjust with the form[^].
(Sorry it is C#, but I believe you can easily understand it, because I feel you have enough qualification, please see below.)

See also:
GUI Apperance - C#.Net[
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900