我想知道是否可以使用vb.net或C#将类型字符串变量转换为windows.form。
我使用的功能和子。
Function createButton(dynamicBtn As String) As BarButtonItem
Dim propButton() As String = Split(dynamicButton, "|", 5) 'Divide data of BD to apply in buttons properties
buttonCreated = New BarButtonItem With {.Name = propButton(0), .Caption = propButton(1), .Visibility = CType(propButton(2), BarItemVisibility), .LargeGlyph = Image.FromFile(String.Format("{0}\{1}", Application.StartupPath, propButton(3)))} 'Create new button with the properties of the BD
formOfTarget.Add(propButton(0), "string to form") 'Variable type dictionay(of string, string) declared before to store the name of button and the name of form to de button.
AddHandler buttonCreated.ItemClick, AddressOf buttonCreated_itemClick
Return buttonCreated
End Function
Private Sub buttonCreated_itemClick(sender As Object, e As ItemClickEventArgs)
If formOfTarget.ContainsKey(CType(e, ItemClickEventArgs).Item.Name) Then
Dim targetOfButton = formOfTarget.Item(CType(e, ItemClickEventArgs).Item.Name)'Here I need get the value of string in the dictionary thats contains the name of form previous created with all constrols and show
formOfTarget.MdiParent = Me
formOfTarget.Show()
formOfTarget.BringToFront()
End If
End Sub
@Enigmativity很抱歉这个混乱。
“要形成的字符串”是已存在的表单的名称。
示例:frmListCustomer.vb
我将菜单信息存储在DB中,如下所示:
“BtnListCustomer | Customers | 0 | resources / customers.png | frmListCustomers“
在哪里:
BtnListCustomer =按钮的名称
客户=按钮标签
0 =如果启用或禁用
Resources / customers.png =中的图标 按钮FrmListCustomers =您显示的表单的名称 单击按钮
使用createButton()函数,我拆分了这个字符串,挂载按钮并在字典中保存按钮名称和表单名称。
FormOfTarget.Add ("btnListCustomer", "frmListCustomer")
Key =“btnListCustomer”
Value =“frmListCustomer”
首先,我将字典声明为(Of string,string)
我的问题在这里。我需要一种方法(如果有的话)将“btnListCustomer”键引用的值“frmListCustomer”转换为表单类型。因此我声明了变量:
Dim targetOfButton = formOfTarget.Item (CType (and, ItemClickEventArgs) .Item.Name)
哪个应对应:
Dim targetOfButton = frmListCustomer 'class of the form frmListCustomer.vb created in the project and so show it as triggered button
TargetOfButton.mdi_parent = me 'frmListCustomer.mdi_parent = me
TargetOfButton.show () 'frmListCustomer.show ()
很抱歉解释中的混乱。这是我的第一篇文章。
答案 0 :(得分:3)
我用反射解决了。
Key.compareTo()