Align controls to center in a FlowLayout

后端 未结 7 818
一向
一向 2020-12-30 01:47

I have a flowlayout as follows:

\"enter

I need to center all the controls on t

相关标签:
7条回答
  • 2020-12-30 02:54

    Create empty Label with Name = lblEmpty and AutoSize = False. Put this control first in controls list in FlowLayoutPanel1, then add code below.

    Example: Assuming three existing labels in FlowLayoutPanel1, the result should be lblEmpty, LabelExisting1, and LabelExisting2, in that order.

    Dim MarginLabelEmpty As Integer = ((FlowLayoutPanel1.Width - (LabelExisting1.Width + LabelExisting2.Width)) / 2)
            lblEmpty.Width = MarginLabelEmpty
    

    I solved my problem by creating this code.

    in your case with Button Controls, create 4 new labels with .Text=""(empty) and put each one at the beginning of each button, naming labels as follows: lblEmpty1, lblEmpty2, lblEmpty3, lblEmpty4.

    Then Add the following code:

    Dim MarginLeftbtnOptAll As Integer = ((FlowLayoutPanel1.Width - btnOpt1.Width) / 2)
            lblEmpty1.AutoSize = False
            lblEmpty1.Width = MarginLeftbtnOptAll
            lblEmpty2.AutoSize = False
            lblEmpty2.Width = MarginLeftbtnOptAll
            lblEmpty3.AutoSize = False
            lblEmpty3.Width = MarginLeftbtnOptAll
            lblEmpty4.AutoSize = False
            lblEmpty4.Width = MarginLeftbtnOptAll
    

    This center button, increasing the width of the empty label according to the width of the FlowLayoutPanel1

    0 讨论(0)
提交回复
热议问题