FlowControlPanel control alignment help

DouglasBell

Active member
Joined
Aug 16, 2011
Messages
38
Programming Experience
Beginner
Hi All

I am trying to automatically create a series of 2 labels on a FlowControlPanel but I just cant get the allignment correct.

I have the following coded.

VB.NET:
Dim x As Integer
                      For x = 0 To 50
                    Dim lbl As New Label()
                    Dim Tlbl As New Label
                    With lbl
                        .Size = New Size(400, 20)
                        .BackColor = Color.FromKnownColor(KnownColor.ControlLight)
                        .FlatStyle = FlatStyle.Flat
                        .Font = New System.Drawing.Font("Century", 12)
                        .TextAlign = ContentAlignment.MiddleLeft
                        .Margin = New Padding(124, 10, 0, 0)
                        .Text = "Downtime " & x
                   End With

                    With Tlbl
                        .Size = New Size(100, 20)
                        .BackColor = Color.FromKnownColor(KnownColor.ControlLight)
                        .FlatStyle = FlatStyle.Flat
                        .Font = New System.Drawing.Font("Century", 12)
                        .TextAlign = ContentAlignment.MiddleLeft
                        .Margin = New Padding(10, 10, 0, 0)
                        .Text = "Time " & x
                    End With

                    DataFLP.Controls.Add(lbl)
                    DataFLP.Controls.Add(Tlbl)
                Next

This basically creates a series of 2 labels that span horizontally as I have it set to Top Down, so that I get a horizontal Scroll bar instead of vertical.

All the controls are added fine but the problem I am having is all the tlbl labels are added next to my lbl labels but under the lbl label. I want my labels side by side not side then under.

I want the Time Labels and the Downtime labels alligned side by side.

I have played with the padding and margins but just cant get them alligned, I have attached a picture of what I am getting and what I am looking for.

Example.jpg

Cheers

Dj
 
If you want the two Labels to act as a single unit then make them a single unit. Create a UserControl with two Labels on it and then add multiple instances of that UserControl to your FlowLayoutPanel. You would expose the Text properties of the two Labels via properties of the UserControl, e.g.
Public Property Label1Text() As String
    Get
        Return Label1.Text
    End Get
    Set(value As String)
        Label1.Text = value
    End Set
End Property
 
@jmcilhinney

Thankyou. I never even gave creating my own control a thought, I have just created a test control and it does exactly what I need.

Thanks

Dj
 
Back
Top