3

行を動的に追加してTableLayoutPanelいますが、高さを設定できません。

コードは長く見えるかもしれませんが、非常に単純です。

コードについての説明:

コードは を作成し、そのTableLayoutPanelプロパティを設定します。その後、コードはデータベースにある映画の数に応じて を作成Pictureboxesします。aと aLabelsを作成した後、コードはそれらの両方をa に配置し、コードは をに挿入します。問題は行の高さです。PictureboxLabelPanelPanelTableLayoutPanel

出力:

ここに画像の説明を入力

私が使用しているコードは次のとおりです。

 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

前もって感謝します!

4

2 に答える 2

9

これを試して :

For Each RS As RowStyle In tablePanel.RowStyles    
     RS.SizeType = SizeType.Absolute         
     RS.Height = 180    
Next
于 2013-02-05T16:49:15.620 に答える
3

答えが出ました。行の高さを設定するには、これを追加するだけです:

tablePanel.RowStyles.Add(New RowStyle(SizeType.Absolute, 150))

を に追加したに、この行を追加する必要があります。PanelTableLayoutPanel

スニペット:

        '.... THE CODE ABOVE CAN BE SEEN IN THE QUESTION POST
        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
        tablePanel.RowStyles.Add(New RowStyle(SizeType.Absolute, 150))
        'here we add a handler for the picture boxs click event
        AddHandler myPicture.Click, AddressOf MyPictureClickEvent
    Next

    Me.Controls.Add(tablePanel)
End Sub

誰かを助けることを願っています

于 2013-02-05T16:55:41.763 に答える