vb.net VB.Net动态添加图片框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24061036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding picture boxes dynamically in VB.Net
提问by Splonkeydonkey
I'm sure there is someone out there who can explain this clearly.
我敢肯定,有人可以清楚地解释这一点。
I would have assumed that I could simply use:
我会假设我可以简单地使用:
Dim pb As PictureBox
then I could use
然后我可以使用
pb = New PictureBox
but apparently not.
但显然不是。
I would also assume I can set parameters
我还假设我可以设置参数
pb.Width
pb.Height
pb.Top
pb.Left
etc.
等等。
If anyone can help me create a picture box dynamically where I can set the properties I would be so grateful, thanks.
如果有人能帮我动态创建一个图片框,我可以在其中设置属性,我将不胜感激,谢谢。
I'm also sorry if this question has already been asked, but I have been looking for a few hours now and nothing has worked for me.
如果已经有人问过这个问题,我也很抱歉,但我已经找了几个小时了,但没有任何效果。
回答by Piratica
In other words, you are trying to add a control to a windows form programmatically. Of course I don't know what you have tried, but I would use:
换句话说,您正在尝试以编程方式向 Windows 窗体添加控件。当然,我不知道您尝试过什么,但我会使用:
Dim pb As New PictureBox
pb.Width = 100 'or whatever
pb.Height = 200
pb.Top = 50 'or whatever
pb.Left = 50
pb.ImageLocation = "dog.png"
Me.Controls.Add(pb)

