开发者

Hide standard form properties in VB.Net using an interface

In VBA you c开发者_运维技巧an have a Userform implement a custom interface and only the properties defined in the interface will show in the VBA Intellisense for the Userform. I tried to duplicate this functionality in VB.Net (2010) and all the base Form properties still show.

Public Interface iTest
    Property TestString As String
End Interface

Public Class Form1
    Implements iTest
    Public Property TestString As String Implements iTest.TestString
        Get
            TestString = Me.txtTest.Text
        End Get
        Set(ByVal value As String)
            Me.txtTest.Text = value
        End Set
    End Property
End Class

An answer to a similar question from Richard Hein is here, but it's for c# and a usercontrol, and I'm unable to convert it.


 Dim itf As iTest = New Form1()
 itf.[and here you'll only see the iTest members show up]


If you cast the form instance directly to your Interface, then you will have intellisense only for the interface members.

For example:

Dim f1 As New Form1()
f1.ShowDialog() 'etc will show here
Dim f1AsiTest As iTest = CType(f1, iTest)
f1AsiTest.TestString = "test1" 'only member available

or

Dim f2 As iTest = New Form1()
f2.TestString = "test2" 'only member available
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜