调整大小代码中的问题 [英] proplem in Resize code

查看:56
本文介绍了调整大小代码中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

推荐答案

好吧,如果您有许多控件,它实际上可能会缓慢运行.至少在原则上,调整大小的工作原理表明您没有无限的递归,这是因为尝试更改表单的大小以响应调整大小,这已经很好了. :-)

但是从设计的角度来看,这通常是错误的方法.通常,您不应完全处理Resize,也不应对此事件做出任何反应.相反,您应该开发可自行调整表单大小的布局.这个想法是摆脱任何绝对定位并设置所有或大部分Size属性.相反,您应该使用嵌套面板的层次结构以及属性DockPadding的组合.
请查看我过去的回答以及有关以下主题的建议:
当屏幕分辨率改变时,Zom Out发生故障 [ ^ ].

在这里,您将找到基本的代码示例:
如何停靠按钮,以便它可以使用以下格式进行调整 [ GUI外观-C#.Net [
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[


这篇关于调整大小代码中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆