Visual Basic 中的动态图片框 [英] Dynamic PictureBox in Visual Basic

查看:40
本文介绍了Visual Basic 中的动态图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个带有图片框的表单,并希望在程序运行时在表单上动态创建另一个图片框(在静态的左侧).我写了这段代码:

I've created a form with a PictureBox on it and would like to dynamically create another PictureBox on the form while the program runs (to the left of the static one). I've written this code:

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()

当我运行此代码时,我可以检测到临时图片框确实已创建.但是,它不会呈现在表单上.它似乎在那里,但看不见.

When I run this code I can detect that the temp PictureBox does get created. However, it is not rendered onto the form. It seems like it's there but is invisible.

有人知道我做错了什么吗?

Does anyone have an idea of what I'm doing wrong?

推荐答案

需要将其添加到表单的控件集合中:

You need to add it to the form's control collection:

Me.Controls.Add(temp)

这篇关于Visual Basic 中的动态图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆