Adding multiple pictureboxes to a form programmatically in vb.net ?

夙愿已清 提交于 2019-12-24 13:22:46

问题


i have to add pictueboxes in to a panel as per my requirement .

"Adding multiple pictureboxes to a form programmatically in vb.net " In this question PictureBox are drawn in random but i want it in a synchronous way enter code here

Dim i As String = ListBox1.Items.Count
For j As Integer = 0 To i
Dim PicBox As New PictureBox
PicBox.Width = 40
PicBox.Top = 25
PicBox.Left = j + 15
PicBox.SizeMode = PictureBoxSizeMode.StretchImage
PicBox.BorderStyle = BorderStyle.FixedSingle
Me.Panel1.Controls.Add(PicBox)
Next

i want to use counter which automatically check the value of i ?

Any idea or suggestion ?

Thank you


回答1:


How about something like this:

Private Sub PicBoxTestButton_Click(sender As System.Object, e As System.EventArgs) Handles PicBoxTestButton.Click
    Try
        Dim numberOfPics As Integer = ListBox1.Items.Count
        Dim lastLeft As Integer = 15
        Const spacer As Integer = 5
        For parser As Integer = 0 To numberOfPics
            Dim PicBox As New PictureBox
            PicBox.Width = 40
            PicBox.Top = 25
            PicBox.Left = lastLeft
            lastLeft = PicBox.Width + PicBox.Left + spacer
            PicBox.SizeMode = PictureBoxSizeMode.StretchImage
            PicBox.BorderStyle = BorderStyle.FixedSingle
            Me.Panel2.Controls.Add(PicBox)
        Next
    Catch ex As Exception
        MessageBox.Show(String.Concat("An error occurred: ", ex.Message))
    End Try
End Sub


来源:https://stackoverflow.com/questions/31244018/adding-multiple-pictureboxes-to-a-form-programmatically-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!