Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set row's height in TableLayoutPanel

I'm dynamically adding rows into my TableLayoutPanel but I just can't configure there height.

The code might look long, but it's a very simple one.

An explanation about the code:

The code creates a TableLayoutPanel and set it's properties. After that, the code creates Pictureboxes and Labels according to how many movies there are in the database. After creating a Picturebox and a Label the code puts both of them in a Panel and then the code inserts the Panel into the TableLayoutPanel. The problem is the row's height.

The output:

enter image description here

Here is the code I'm using:

 Dim movieN As Integer = MoviesDataSet.movies.Rows.Count
    Dim tablePanel As New TableLayoutPanel

    With tablePanel
        .Size = New Point(Me.ClientRectangle.Width - 10, Me.ClientRectangle.Bottom - 55)
        .ColumnCount = 4
        .GrowStyle = TableLayoutPanelGrowStyle.AddRows
        .AutoScroll = True
        .Margin = New System.Windows.Forms.Padding(0)
        .Location = New System.Drawing.Point(5, 50)
        .CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset
        .ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0!))
        .ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0!))
        .ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0!))
        .ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0!))
        .Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top
    End With


    For Each MovieRow As DataRow In MoviesDataSet.Tables("movies").Rows
        'define two new controls to be added
        Dim myLabel As New Label
        Dim myPicture As New PictureBox
        Dim container As New Panel

        'set the properties of the new controls
        myLabel.Text = MovieRow("movieName")
        myLabel.AutoSize = True
        myLabel.Location = New System.Drawing.Point(30, 110)
        With myPicture
            .Image = Image.FromFile(MovieRow("moviePhoto"))
            .Tag = MovieRow("ID")
            .Size = New System.Drawing.Size(100, 100)
            .SizeMode = PictureBoxSizeMode.StretchImage
            .Location = New System.Drawing.Point(2, 2)
            .Cursor = Cursors.Hand
        End With

        'here we add the controls to a layout panel to
        'manage the positioning of the controls
        With container
            .Dock = DockStyle.Fill
            .Margin = New System.Windows.Forms.Padding(0)
            .Controls.Add(myPicture)
            .Controls.Add(myLabel)
        End With


        With tablePanel.Controls

            .Add(container)

        End With

        'here we add a handler for the picture boxs click event
        AddHandler myPicture.Click, AddressOf MyPictureClickEvent
    Next

    Me.Controls.Add(tablePanel)
End Sub

Thanks in advance!

like image 207
kfirba Avatar asked Dec 01 '25 14:12

kfirba


1 Answers

Try This :

For Each RS As RowStyle In tablePanel.RowStyles    
     RS.SizeType = SizeType.Absolute         
     RS.Height = 180    
Next
like image 175
Abdusalam Ben Haj Avatar answered Dec 04 '25 00:12

Abdusalam Ben Haj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!