Is it possible to add a link to some source code for inclusion in the source file in vb.net, winforms?

I don't know what it's called, so I struggled to find an answer from google, but I have a vague memory of this from t'old days.

I have subclassed (* see below) about 8 map controls, redefined some properties and added some functionality to each of them. The changes I made are identical in each case. If I made a change, I have to go through each class and apply the same change there. I was hoping there might be a keyword such as <IncludeSourcefile "common.vb> that can be placed in each class.

Is there any chance?

(* note) I use the term sub-classed, but I do not know if this is the correct terminology. I also saw that it was used for callbacks. Is the correct term for use subclassed?

+5
source share
6 answers

I seriously doubt what work out for you. You cannot use the include file to hush changes in the derivatives of a control. Usually, you make changes to a common base class, for example, a derivative of Control, and then derive individual controls from this base class. But this will not work if you set up 8 separate management classes. Copy and paste is your party.

+1
source

, ...

  • common.vb , .
  • , .
  • , common.vb
  • , .

, , .

, , , VB.NET . , ...;-D

+1

nobugz. #Include, , . include 8 .

: , , - , :

Class CommonChanges

    Private Readonly WithEvents DerivedUserControl As Windows.Forms.Control

    Public Sub New(ByVal derivedUserControl As Windows.Forms.Control)
        Me.DerivedUserControl = derivedUserControl
    End Sub

    Private Sub DerivedUserControl_OnClick(sender As Object, e As EventArgs) _
                Handles DerivedUserControl.Click
        ' ... '
    End Sub

    ...  ' (more event handlers with common code go here) '

End Class

8 , :

Class MyDerivedUserControl
    Extends Button  ' (or whatever control it extends) '

    Private ReadOnly Changes As CommonChanges

    Public Sub New
        Changes = New CommonChanges(Me)
        ' ^ 'CommonChanges' will subscribe to this class events and possibly
        '   apply other changes to the control object 'Me'.
        ...
    End Sub
End Class

Changes CommonChanges MyDerivedUserControl , CommonChanges .

, Control, CommonChanges .

+1

, - , Microsoft ( , #), .

, , ++, .

OO , .

:

class CommonCode
{
    public void HandlePaint(Control c, PaintEventArgs a)
    {
        // Do shared code
    }
    public void HandleResize(Control c)
    {
        // Do shared code
    }

}

class MyButton : Button
{
    private CommonCode m_common=null;

    public MyButton()
    {
        m_common=new CommnCode();        
    }
    protected override OnPaint(PaintEventArgs a)
    {
        m_common.HandlePaint(this,a);
    }

    protected override void OnResize(EventArgs e)
    {
        m_common.HandleResize(this);
    }

}

class MyTextbox :Textbox
{

    private CommonCode m_common=null;

    public MyTextbox()
    {
        m_common=new CommnCode();        
    }
    protected override OnPaint(PaintEventArgs a)
    {
        m_common.HandlePaint(this,a);
    }

    protected override void OnResize(EventArgs e)
    {
        m_common.HandleResize(this);
    }

}
+1

DLL.

DLL Visual Studio, "" .

, DLL.

0

( dll) visual studio:

, , ( ):

→ → → MyClassLibrary

In order to be able to find MyClassLibrary on the project tab, both projects must be in the same solution - otherwise you can just “browse” and point to the DLL itself.

Then in the .vb file you need to use your classes, you can import MyClassLibrary:

// assuming the namespace is MyClassLibrary
imports MyClassLibrary

At this point, you can simply use your subclasses and controls. If you go MyClassLibrary., intellisense will show you all your classes.

0
source

All Articles