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") 展开
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") 展开
1个回答
展开全部
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询