我已经创建了一个带有PictureBox的表单,并且希望在程序运行时(在静态程序的左侧)动态地在表单上创建另一个PictureBox。我写了这段代码:
Dim temp As PictureBox
temp = New PictureBox
temp.Image = StaticPictureBox.Image
temp.Visible = True
temp.Top = StaticPictureBox.Top
temp.Width = StaticPictureBox.Width
temp.Height = StaticPictureBox.Height
temp.Left = StaticPictureBox.Left - 20
temp.BringToFront()
当我运行此代码时,我可以检测到临时PictureBox是否已创建。但是,它不会呈现在表单上。它似乎在那里,但是看不见。
有没有人知道我做错了什么?
答案 0 :(得分:4)
您需要将其添加到表单的控件集合中:
Me.Controls.Add(temp)
答案 1 :(得分:0)
为什么不直接删除该代码并将一个图片框放在另一个旁边并设置:
newpicturebox.visible = false
然后,只要您完成操作,就可以更改:
newpicturebox.visible = true
答案 2 :(得分:0)
我知道这已经过时了但是......你在这里遇到了错误:
temp.Left = StaticPictureBox.Left - 20
应该是:
temp.Left = StaticPictureBox.right + 20
或:
temp.Left = StaticPictureBox.right
希望它有所帮助。