Vb.net 如何从Me.ActiveControl获取属性值
我用_Keydown处理程序对表单进行了子类化,它在不同的情况下应该有不同的行为。为此,我在子类中编写了如下代码:Vb.net 如何从Me.ActiveControl获取属性值,vb.net,Vb.net,我用_Keydown处理程序对表单进行了子类化,它在不同的情况下应该有不同的行为。为此,我在子类中编写了如下代码: If Me.ActiveControl.GetType Is GetType(TextBox) Then End if 如果我必须检查textbox是否为多行,那么我会尝试: If Me.ActiveControl.GetType Is GetType(TextBox) Then If Me.ActiveControl.Multiline = True Then ...
If Me.ActiveControl.GetType Is GetType(TextBox) Then
End if
如果我必须检查textbox是否为多行,那么我会尝试:
If Me.ActiveControl.GetType Is GetType(TextBox) Then
If Me.ActiveControl.Multiline = True Then ...
但这并没有发生(程序看不到我的文本框的属性)
如何在这种情况下(从Me.ActiveControl)获得“Multiline”之类的属性?您仍然需要将其转换为实际的控件类型 即:
我会这样做:
If Me.ActiveControl Is TextBox Then
If DirectCast(Me.ActiveControl, TextBox).MultiLine Then
'your code here
End If
End If
@用户973238无需担心。这是实现这一目标最干净的方法。
If Me.ActiveControl Is TextBox Then
If DirectCast(Me.ActiveControl, TextBox).MultiLine Then
'your code here
End If
End If