从“控件数组"创建控件? [英] Creating control from 'control array?'

查看:106
本文介绍了从“控件数组"创建控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列的图片框:

    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.

这篇关于从“控件数组"创建控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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