区分vb.net中的对象子类型 [英] Distinguishing between object subtypes in vb.net
问题描述
大家好,
我需要能够让我的应用程序区分对象子类型,以便我可以使用System.Speech.Synthesis来说出文本不同的属性取决于鼠标与哪种控件进行交互。 例如,我的应用程序
有一个MenuStrip,两个ToolStrips和一个StatusStrip控件。 我知道我可以使用这样的代码:
Public Sub SetToolbarStatus(ByVal senderComponent As Component,ByVal strMessage As String)
如果不是mControlLookup.Contains(senderComponent)那么
mControlLookup.Add(senderComponent,strMessage)
Dim pToolStripItem As ToolStripItem = CType(senderComponent,ToolStripItem)
如果pToolStripItem IsNot Nothing那么
AddHandler pToolStripItem.MouseMove,AddressOf Handle_ToolSelect
AddHandler pToolStripItem.MouseLeave,AddressOf Handle_ToolLeave
AddHandler pToolStripItem.MouseEnter,AddressOf Handle_ToolEnter
Else
mControlLookup(senderComponent)= strMessage
End If
Else
mControlLookup(senderComponent)= strMessage
End if
End Sub
将属性添加到所有三种类型控件,但如何使鼠标与ToolStripMenuItem或ToolStripStatusLabel交互时,扬声器的提示设置为Text属性,但如果是常规ToolStrip,则提示
到项目的而不是ToolTipText属性?我的工具条在按钮和DropDownButtons上有图像,没有显示文本,所以我看不需要在它们上设置Text属性。
谢谢,
Jason
您好
你可以考虑使用各种控件的Tag属性。 ToolStrip的所有子类型都具有这样的属性,您的语音代码可以轻松地从任何控件获取Tag属性,并且可能省去必须区分控制位置
(Form,ToolStrip等)
Hi all,
I need to be able to get my application to distinguish between object subtypes so that I can use System.Speech.Synthesis to speak the text of a different property depending on what kind of control the mouse is interacting with. For example, my application has a MenuStrip, two ToolStrips, and a StatusStrip control. I know that I can use code like this:
Public Sub SetToolbarStatus(ByVal senderComponent As Component, ByVal strMessage As String) If Not mControlLookup.Contains(senderComponent) Then mControlLookup.Add(senderComponent, strMessage) Dim pToolStripItem As ToolStripItem = CType(senderComponent, ToolStripItem) If pToolStripItem IsNot Nothing Then AddHandler pToolStripItem.MouseMove, AddressOf Handle_ToolSelect AddHandler pToolStripItem.MouseLeave, AddressOf Handle_ToolLeave AddHandler pToolStripItem.MouseEnter, AddressOf Handle_ToolEnter Else mControlLookup(senderComponent) = strMessage End If Else mControlLookup(senderComponent) = strMessage End If End Sub
to add a property to all three types of controls, but how do I make it so that if the mouse interacts with a ToolStripMenuItem or a ToolStripStatusLabel the speaker's prompt is set to the Text property, but if it's a regular ToolStrip, the prompt is set to the item's ToolTipText property instead? My Toolstrips have images on the Buttons and DropDownButtons with no displayed text so I saw no need to set the Text property on them .
Thanks,
Jason
Hi
You could consider using the Tag property of the various controls. All the subtypes of a ToolStrip have such a property, and your speech code could easily get the Tag property from any control and perhaps saving on having to differentiate the control location (Form, ToolStrip etc)
这篇关于区分vb.net中的对象子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!