Results 1 to 3 of 3

Thread: [RESOLVED] Set Location of controls on a flowlayoutpanel

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    13

    Resolved [RESOLVED] Set Location of controls on a flowlayoutpanel

    Hello
    Once again my Googling skills have failed me. Is there a way to set the location of controls that are inside a flowlayout panel? I would like a label to be centered (from top and left) on a dynamically created flowlayoutpanel. I'm trying to make very simple shop drawings (yes I am using a flowlayout panel to make shop drawings) and I'd like the label in the middle. I have 2 text boxes that set the width and height of the panels, 1 that sets the Number of panels, and 1 that sets the Label of the panel. Forgive the code I have been trying many things I've found.
    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            'generate panels
    
            Dim pc As Integer = TxtPanelCount.Text
            GeneratePanels(pc)
        End Sub
      Private Sub GeneratePanels(ByVal totalPanels As Integer)
            Dim psw As Integer = TxtWidth.Text
            Dim psh As Integer = TxtHeight.Text
            Dim lbw As Integer = psw / 2
            Dim lbh As Integer = psh / 2
            For i As Integer = 1 To totalPanels
                Dim fl As New FlowLayoutPanel
    
                fl.Size = New Size(psw, psh)
                fl.BackColor = Color.Khaki
                fl.Margin = New Padding(0)
                'fl.Dock = DockStyle.Fill
                fl.BorderStyle = BorderStyle.FixedSingle
                fl.Cursor = Cursors.Hand
                Dim lbl As New Label
                lbl.Text = TxtLabel.Text
                lbl.AutoSize = False
                lbl.Anchor = AnchorStyles.None
                lbl.Location = New Point(lbw, lbh)
                'lbl.Left = fl.Width - lbl.Width / 2
                'lbl.Top = fl.Height - lbl.Height / 2
                'lbl.TextAlign = ContentAlignment.MiddleCenter
                fl.Controls.Add(lbl)
                Flpanels.Controls.Add(fl)
    
    
            Next
        End Sub
    That code works but everything I've tried always puts the label at the top.
    Thanks for any help.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Set Location of controls on a flowlayoutpanel

    The whole point of a FlowLayoutPanel is that the layout flows. If that's not what you want then don't use a FlowLayoutPanel. Why exactly are you using a FlowLayoutPanel in the first place? Please provide ALL the relevant information.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    13

    Re: Set Location of controls on a flowlayoutpanel

    Thanks! I forgot the controls inside the flowlayoutpanel also flows. I just made the label half the size of the panel and set it's textalign to bottom. I just needed a simple way to make shop drawings for my business without using graphics. Set the flowlayoutpanels border to fixed single and it works great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width