Adding picture boxes dynamically in VB.Net

只愿长相守 提交于 2021-01-28 02:50:49

问题


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.


回答1:


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:

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)


来源:https://stackoverflow.com/questions/24061036/adding-picture-boxes-dynamically-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!