我想创建一个wysiwyg android布局xml编辑器。我有一个类button(),它包含可放置在布局(textcolour,size,position等)上的按钮的所有relavent属性。 当用户单击表单上的按钮时,会在编辑器视图中添加一个新按钮。我希望能够为布局中的每个按钮创建此类的新实例,以便它们可以写入xml文件。然而,声明实例时,我希望能够将它们命名为Button1的,BUTTON2等也许一些代码会更有意义...:你可以在vb.net的声明语句中的新变量的标识符中包含其他变量的值吗?
Public Class button 'The class where all the properties for the button are defined
...
End Class
Public Partial Class MainForm 'The mainform class
Dim btnclassno As Integer = 0 'The number of button() classes made
...
Sub btnAddButtonClick(sender As Object, e As EventArgs)
btnclassno += 1 'Changes it by 1
Dim (newbutton & btnclassno) As button = New button()'Defines a new instance of the class called newbutton and then the value of btnclassno (e.g. newbutton1, newbutton2 etc.)
...
End Sub
End Class
我想知道这甚至有可能,和如果是这样做,或者甚至更好的一种更有效的方法来创建类的新实例而不使用硬编码名称(我对类的概念相对陌生,所以我不太了解如何使用它们)。 谢谢。
这是可以做到,但我必须要问,为什么? – Brian