什么是指定可枚举 Windows 控件的接口?
我有一个验证组合框控件的方法,如下所示:
Public Function ValidateComboBox(ByVal objMessageMode As Errors.MessageMode, ByVal cboInput As ComboBox) As Boolean
Dim blnValidated As Boolean
'no value--invalidate'
If cboInput.SelectedValue Is Nothing Then
Errors.InvalidateField(cboInput, Errors.errFieldBlank, Me.ErrorProviderPurchaseTag, objMessageMode)
blnValidated = False
'value--validate'
Else
Errors.ValidateField(cboInput, Me.ErrorProviderPurchaseTag)
blnValidated = True
End If
Return blnValidated
End Function
我想要的是能够替换任何控件作为实现“SelectedValue”对象行为的参数。 有我可以指定的接口吗? 谢谢您的帮助!
I have a method that validates a combo box control like so:
Public Function ValidateComboBox(ByVal objMessageMode As Errors.MessageMode, ByVal cboInput As ComboBox) As Boolean
Dim blnValidated As Boolean
'no value--invalidate'
If cboInput.SelectedValue Is Nothing Then
Errors.InvalidateField(cboInput, Errors.errFieldBlank, Me.ErrorProviderPurchaseTag, objMessageMode)
blnValidated = False
'value--validate'
Else
Errors.ValidateField(cboInput, Me.ErrorProviderPurchaseTag)
blnValidated = True
End If
Return blnValidated
End Function
What I want is to be able to substitute any control as a parameter that implements the behavior of the "SelectedValue" object. Is there an interface that I could specify? Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ComboBox 不实现接口,而是继承自抽象类 ListControl 。
ComboBox doesn't implement an interface, but instead inherits from the abstract class ListControl.
我不相信有。 我创建了自己的接口(通常是 I(Product)Field,还包含其他帮助信息),每种不同类型的控件都实现该接口。 然后,在验证中我只是将其转换为该值; 它不是世界上最好的设计,但它却很有魅力。
请注意,这还涉及对每种类型的控件(编辑框、组合框等)进行子类化,但是,我通常已经出于其他目的对它们进行了子类化,所以我不认为这是一个问题。
I don't believe there is. I've created my own interface (usually I(Product)Field that also contains other helper info) that each different type of control implements. Then, in the validation I just cast to that; it's not the best design in the world but it works like a charm.
Note that this also involves subclassing each type of control (edit box, combo box, etc) but, I'm usually already subclassing them for other purposes so I don't consider this is a problem.