VB.net动态添加带有标签和滚动条的Picturebox

时间:2015-09-14 20:39:59

标签: vb.net dynamic label scrollbar picturebox

所以基本上我想要完成的是我设置了要添加的Picturebox的总数,每个图片框都有自己的相应标签,如果我们达到6个图像,我们就允许滚动条向下移动。

示例: http://i.imgur.com/5xWu5Y1.png

正如您所看到的,图片会相应地添加标签。 我怎么能在代码中做到这一点?

目前我有这样的事情:

' Total PictureBoxes/Labels to Generate
Dim wTotalPictures = 1

' Original PictureBox Starting Point
Dim wOriginalLocation = New System.Drawing.Point(40, 54)

' Assigned Label Title
Dim wImageTitle As String = "PictureTitle"

Dim wNewImage As New PictureBox
Dim wImageSize = New Size(122, 173)

With wNewImage
    .SizeMode = PictureBoxSizeMode.StretchImage
    .Image = Image.FromFile("C:\Users\Jason\Pictures\newImage.jpg")
    .Location = wOriginalLocation
    .Size = wImageSize
End With

所以任何帮助都将不胜感激!

修改

我现在已经设法将其更改为此,这种方式更好但仍然不是100%自动,就像我想要的那样。

' Total PictureBoxes/Labels to Generate
    Dim i As Integer = 0
    Dim wTotalPictures = 5

    ' Original PictureBox Starting Point
    Dim wOriginalLocation = New System.Drawing.Point(40, 54)

    ' Assigned Label Title
    Dim wImageTitle As String = "PictureTitle"
    Dim wImageSize = New Size(122, 173)

    Dim wNewLocation As Integer = 0

    Do Until i = wTotalPictures

        ' Setup
        Dim wNewImage(i) As PictureBox
        wNewImage(i) = New PictureBox

        ' Execute
        wNewImage(i).SizeMode = PictureBoxSizeMode.StretchImage
        wNewImage(i).Image = Image.FromFile("C:\Users\Jason\Pictures\newImage.jpg")
        wNewImage(i).Size = wImageSize

        If wNewLocation < 480 Then
            wNewImage(i).Location = New System.Drawing.Point(40 + wNewLocation, 54)
        ElseIf wNewLocation = 480 Then
            wNewImage(i).Location = New System.Drawing.Point(40, 258)
            wNewLocation = 0
        End If

        ' Add to Form
        MyTab.Controls.Add(wNewImage(i))
        wNewImage(i).BringToFront()

        wNewLocation = wNewLocation + 160
        i += 1
    Loop

请帮助,谢谢!

0 个答案:

没有答案