Search code examples
vb.netvisual-styles

Warning BC42025 when trying to applying VisualStyler.ApplyExcludeTag() method to Tab Control


I try to apply SkinSoft.VisualStyler.ApplyExcludeTag(control As Control, childControls As Boolean) method to Tab Control to disable Skin for this control as below code:

Private Sub MaintenanceProgramForm_Load(sender As Object, e As EventArgs) 
    vssfVisualStyler.ApplyExcludeTag(FormClientsAndSites.tabClientsAndSites, False)
    'Some Code
End Sub

I received this warning:

BC42025: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.

How can I disable this warning?


Solution

  • The warning occurs just to inform you that the ApplyExcludeTag() method is shared and thus doesn't need an instance of its containing class in order to be called.

    Just call it on the class directly:

    VisualStyler.ApplyExcludeTag(FormClientsAndSites.tabClientsAndSites, False)
    

    EXPLANATION

    Since you seem to be unaware of how Shared members work, here's a brief explanation:

    Marking something as Shared makes it so that you don't need a specific instance in order to access a method, field or property of that type.

    For example, instance methods work like this:

    Public Class SomeClass
        Public Sub SayHello()
            MessageBox.Show("Hello World!")
        End Sub 
    End Class
    

    In order to call this you first need to initialize an instance of the SomeClass class:

    Dim cls As New SomeClass
    cls.SayHello() 'Opens a message box that says "Hello World!".
    

    However, when marking a method as Shared you no longer need to create an instance before being able to call it:

    Public Class SomeClass
        Public Shared Sub SayHello()
            MessageBox.Show("Hello World!")
        End Sub 
    End Class
    
    SomeClass.SayHello() 'Opens a message box that says "Hello World!".
    

    Based on the warning you got, we know that ApplyExcludeTag() is marked as Shared.