VB.NET 窗体里动态添加几个GroupBox控件然后再GroupBox里动态添加几个PictureBox控件,重定路径有问题

'大师们帮查看是不是缺少什么定义之类的,重点在最后面,PictureBox重新定义路径有问题,DimGrouAsNewList(OfGroupBox)PrivateSub... '大师们帮查看是不是缺少什么定义之类的,重点在最后面,PictureBox 重新定义路径有问题,

Dim Grou As New List(Of GroupBox)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

For i As Integer = 1 To 3 '

Dim b As New GroupBox

With b '设置图片框属性

.Location = New Point((i - 1) * 362 + 12, 12)

.Size = New Point(357, 222)

.Text = "GroupBox" & i

.Name = "GroupBox" & i

End With

Me.Controls.Add(b) '在窗体上添加 控件

Grou.Add(b)

Next

end sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Dim css As Int16

css = 0

For i As Integer = 1 To 6 '循环创建 图片框

Dim b As New PictureBox

With b '设置图片框属性

.Name = "PictureBox " & i

.Text = .Name

.Location = New Point((i - 1) * 51 + 38, 59)

.SizeMode = PictureBoxSizeMode.StretchImage

.Size = New Point(26, 22)

.Image = Image.FromFile(Application.StartupPath & "\1.JPG") '

End With

Me.Grou(css).Controls.Add(b)

Next

end sub

,想把第2个GroupBox里的第3个PictureBox重新定义图片路径,以下程序试过行不通

Me.Grou(0).Controls(8).Image = Image.FromFile(Application.StartupPath & "\3.JPG")
Me.Grou(1).Controls(2).Image = Image.FromFile(Application.StartupPath & "\3.JPG")
展开
 我来答
11_88
2016-09-06 · TA获得超过115个赞
知道小有建树答主
回答量:89
采纳率:100%
帮助的人:78.9万
展开全部
        If Grou(0).Controls.Count >= 8 AndAlso Grou(0).Controls(8).GetType.Name.Equals("PictureBox") Then
            Dim PictureBox As PictureBox = TryCast(Grou(0).Controls(8), PictureBox)
            PictureBox.Image = Image.FromFile(Application.StartupPath & "\3.JPG")
        End If
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式