3

各セルに+を付けようとしていTableLayoutPanelます。大丈夫ですが、セルのサイズを同じに設定することはできません! 無限の数の行を持つ4つの列を作成しようとしています.幅が幅よりも小さい場合を除き、セルを幅に合わせたいと思います.PictureBoxLabelLabelLabelPicture

今のところ、私のコードはほとんど機能しますが、方法がわからないため、セルサイズを設定していません。

これが私のコードです:

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim movieN As Integer = MoviesDataSet.movies.Rows.Count
    Dim tablePanel As New TableLayoutPanel

    With tablePanel
        .Size = New Point(650, 450)
        .ColumnCount = 4
        .GrowStyle = TableLayoutPanelGrowStyle.AddRows
        .AutoScroll = True
        .Margin = New System.Windows.Forms.Padding(0)
        .Location = New System.Drawing.Point(5, 50)
        .CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset
    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.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)
        End With

        'here we add the controls to a flow layout panel to
        'manage the positioning of the controls but you could
        'explicitly set the location of the controls if you 
        'just wanted to add them to the forms controls collection
        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
        AddHandler myPicture.MouseHover, AddressOf MyPictureHoverEvent
    Next
    Me.Controls.Add(tablePanel)
End Sub
4

1 に答える 1

0

セルの幅をPictureBoxまたはの幅と同じにしたい場合Label、それらを でラップして同じセルに配置し、のAutoSizeModeプロパティをにPanel設定し、そのAutoSizeプロパティを に設定します。次に に対して同じことを行うと、 のサイズに応じて各セルが拡大または縮小し、はその中のコントロールのサイズに応じて同じことを行います。PanelAutoSizeMode.GrowAndShrinkTrueTableLayoutPanelPanelPanel

于 2013-05-22T00:03:24.003 に答える