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

问题描述

我的问题是我无法根据表单大小调整表单控件的大小.
我有一个包含文本框,标签和按钮的表单.单击按钮时,我需要以特定大小打开相同的表单,我希望表单的所有控件应与表单和控件内的字体成比例也应按比例显示.任何人都可以建议如何使用代码做到这一点.无法通过使用anchor和dock属性来解决此问题.我的代码

My problem is that i am unable to resize the form control according to the form size.
I have a form which contains a textbox,a label and a button.On button click i need to open the same form in a particular size and i want all the controls of the form should be proportion with the form and the font inside the control should also in proportion.Can any one please suggest how to do that with code.Unable to solve this by using the anchor and dock property.My code

Private Sub Test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim widthRatio As Single = Me.Size.Width / 300.0F
        Dim heightRatio As Single = Me.Size.Height / 300.0F
        Dim scale As New SizeF(widthRatio, heightRatio)
        Me.Scale(scale)
        For Each control As Control In Me.Controls
            control.Scale(scale)
            control.Font = New Font(control.Font.FontFamily,   control.Font.SizeInPoints * widthRatio * heightRatio)
        Next
    End Sub



这里的宽度和高度比例我划分了300.0F,因为我的原始形式是size(300,300),但是这里没有使所有控件均等扩展..
任何建议表示赞赏.

谢谢
pallavi



here for width and height ration i have divided 300.0F because my original form is size(300,300),but here am not getting all the controls expand equally..
any suggestion is appreciated.

thanks
pallavi

推荐答案


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

08-15 11:45