Doug Glancy
Doug Glancy

Reputation: 27488

Hide standard form properties in VB.Net using an interface

In VBA you can 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.

Upvotes: 0

Views: 923

Answers (2)

Hans Passant
Hans Passant

Reputation: 942348

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

Upvotes: 2

Tom
Tom

Reputation: 3374

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

Upvotes: 1

Related Questions