是否可以在类属性中添加字符串? 我想做的是从“我的”类中,我可以获取表单的Text属性。但是对于每个表格,我都必须静态提供表格名称。我想尽力而为。我尝试过的是这里
Dim frmName As New Object
frmName = Name.ToString()
Dim frmProperty As String
frmProperty = "My.Forms." & frmName & ".Text"
frmNameLabelControl.Text = frmProperty
,但在前端显示“ My.Forms.Form1.Text”
答案 0 :(得分:0)
我认为您只需要以下代码。但是您需要在每种表单中以相同顺序创建等效的frmNameLabelControl。例如,成为您在每种表单中创建的最后一个标签
Dim FormsCount As Integer = My.Application.OpenForms.Count
Dim frmProperty As String
Dim lblContrIndex As Integer = 0 ' Number of label creation in descending order
For i As Integer = 0 To FormsCount - 1
frmProperty = My.Application.OpenForms.Item(i).Text
My.Application.OpenForms.Item(i).Controls.OfType(Of Label).ElementAt(lblContrIndex).Text = frmProperty
Next