问题描述
我有一系列的图片框:
Dim pieces(500) As PictureBox
pieces(1) = New PictureBox
With pieces(1)
.CreateControl()
.Visible = True
.BackColor = Color.Red
.Width = 50
.Height = 50
.Left = 50
.Top = 50
End With
程序不会崩溃或发生任何事情,但是在窗体上看不到图片框.我该如何使其正常工作?
The program does not crash or anything, but the picturebox is no where to be seen on the form. How to I make this work correctly?
控制数组"对此是否正确?还是其他?
And is 'Control Array' the correct term for this? or something else?
推荐答案
在将这些PictureBox添加到表单之前,它不会显示.
It won't show up until you add those PictureBoxes to a form.
我想您已经有一个Windows窗体,因此您要做的就是:Window.Controls.Add(PictureBox)
I suppose you already have a Windows Form, so all you have to do is:Window.Controls.Add(PictureBox)
假设您的表单对象称为窗口"
Supposing your form object is called "Window"
您需要一个一个地添加它们,而不必将它们放在数组中,这就是Windows窗体内有一个Control集合的原因
You need to add them one by one and they don't need to be on an array, that's why there's a Control collection inside the Windows Form
控制数组是VB 6术语,在.NET中不再使用. .NET和VB 6之间的编程模型非常不同,您应该花一些时间阅读一本好教程或一本好书.
Control Array is a VB 6 term, is not used in .NET anymore. The programming model between .NET and VB 6 is very different, you should take the time to go through a good tutorial or good book.
这篇关于从“控件数组"创建控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!