簡體   English   中英

在vb.net中調整表格大小時如何調整控件大小?

[英]How to resize controls while resizing form in vb.net?

我正在使用帶有UI控件的vb.net應用程序。如果我調整窗體的大小,則UI控件的對齊方式會發生不正確的變化。 請指導我解決此問題。

Dim CWidth As Integer = Me.Width ' Current Width
Dim CHeight As Integer = Me.Height ' Current Height
Dim IWidth As Integer = Me.Width ' Initial Width
Dim IHeight As Integer = Me.Height ' Initial Height

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    IWidth = Me.Width
    IHeight = Me.Height

End Sub

Private Sub Form4_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    Dim RW As Double = (Me.Width - CWidth ) / CWidth ' Ratio change of width
    Dim RH As Double = (Me.Height - CHeight ) / CHeight ' Ratio change of height

    For Each Ctrl As Control In Controls
        Ctrl.Width += CInt(Ctrl.Width * RW)
        Ctrl.Height += CInt(Ctrl.Height * RH)
        Ctrl.Left += CInt(Ctrl.Left * RW)
        Ctrl.Top += CInt(Ctrl.Top * RH)
    Next

    CWidth = Me.Width
    CHeight = Me.Height

End Sub

請參考我上面的代碼並指導我。

您是否嘗試過使用TableLayoutPanel控件? 您可以向每個單元格添加一個按鈕,然后將TableLayoutPanel錨定到頂部,底部,左側,右側。

然后,這將為您處理按鈕的大小調整-無需任何編碼?

這樣可以解決您的問題嗎? 該圖顯示了停靠在單元格中的兩個按鈕

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM