设计时的控制数组 [英] array of control at design time

查看:74
本文介绍了设计时的控制数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何像VB6一样在设计时创建控件数组?有没有可能?我知道在运行时创建该代码的代码..

How to create array of control in design time as in VB6? Is it possible or not? I know code to create that on run time..

推荐答案

只需将新按钮调暗,然后初始化属性并将其放在表单上.您可以使用Controls属性访问这些控件,但也可以将它们放入数组或列出自己以供参考.请记住,您必须使用控件添加它们.添加,否则您将根本看不到任何新创建的控件.

Simply dim a new button and initialize the properties and place it on the form. You could access these controls by using the Controls property but you could also put them in an array or list yourself for reference. Remember that you must add them using the Controls.Add otherwise you won''t see any of the newly creates controls at all.

Private Sub CreatButton()
        Dim btnYes As System.Windows.Forms.Button
        ' Create control
        btnYes = New System.Windows.Forms.Button()
        ' Set button properties
        btnYes.Name = "ButtonYes"
        btnYes.Size = New System.Drawing.Size(70, 30)
        btnYes.Location = New System.Drawing.Point(300, 30)
        btn.TabIndex = 1
        btnYes.Text = "YES"
        ' add to the parent form's controls collection
        Me.Controls.Add(btnYes)
End Sub



祝你好运!



Good luck!


这篇关于设计时的控制数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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