我想将一个处理程序添加到我通过其名称找到的控件中。问题是无法从 Button 或 RadioButton 或类似的东西对控件进行调暗...
Dim control As Control = FindName(MyObject.Name.ToString)
AddHandler control.MouseEnter, Sub()
Try
Dim Tooltip As New ToolTip()
Tooltip.SetToolTip(control, control.Name.ToString)
Catch
End Try
End Sub
在代码中,我可以将控件调暗为 Button,但随后例如 RadioButtons 将不起作用。而且我不希望有一个总是检查 ObjectType 然后进入 if 部分的代码
If TypeName(MyObject).ToString = "Button" then
...
else if TypeName(MyObject).ToString = "Label" then
...
else if TypeName(MyObject).ToString = "RadioButton" then
...
End If
有没有更好的解决方案然后这样做?
例如像
Dim Control as TypeName(MyObject).ToString = FindName(MyObject.Name.ToString)