Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Com Control/Wrapper/Inherit/etc or another approach?

Status
Not open for further replies.

Sorwen

Technical User
Nov 30, 2002
1,641
US
So I have a COM Control that I need to extend some functionality of. If I understand correctly I can't Inherit from it so I have to create a wrapper. If I understand correctly a wrapper is nothing more than a class that creates an instance of the object and handles the functions and various methods of the object. So If I'm understanding this correctly that is fine. It is a control that during design time or run time needs to display on a form. My though is to make the class inherit from a control so that it can easily be placed on a form and has all methods required of a control so I don't have to create them myself. While I know this will work is this the best way to handle this type of situation or should I take another approach?

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Oh, I forgot to add something. When extending controls that could be added to a status strip I Inherited form a Windows.Forms.ToolStripControlHost. Is there something like this that might be better to Inherit from rather than a control? The implimentation seemed totally different than how I Inherited from before.

Example:
Code:
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

<System.ComponentModel.DesignerCategory("code")> _
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip)> _
Public Class ToolStripStatusNumericUpDown
    Inherits Windows.Forms.ToolStripControlHost

    Public Sub New()
        MyBase.New(New Windows.Forms.NumericUpDown)
    End Sub

    <System.ComponentModel.Browsable(False)> _
    Public ReadOnly Property NumericUpDownControl() As Windows.Forms.NumericUpDown
        Get
            Return CType(Control, NumericUpDown)
        End Get
    End Property

    Public Property Minimum() As Integer
        Get
            Return NumericUpDownControl.Minimum
        End Get
        Set(ByVal value As Integer)
            NumericUpDownControl.Minimum = value
        End Set
    End Property

    Public Property Maximum() As Integer
        Get
            Return NumericUpDownControl.Maximum
        End Get
        Set(ByVal value As Integer)
            NumericUpDownControl.Maximum = value
        End Set
    End Property

    Public Property value() As Integer
        Get
            Return NumericUpDownControl.Value
        End Get
        Set(ByVal value As Integer)
            NumericUpDownControl.Value = value
        End Set
    End Property

    Protected Overrides Sub OnSubscribeControlEvents(ByVal control As System.Windows.Forms.Control)
        MyBase.OnSubscribeControlEvents(control)

        Dim valueNumericUpDownControl As NumericUpDown = CType(control, NumericUpDown)
        AddHandler valueNumericUpDownControl.ValueChanged, AddressOf NumericUpDownControl_ValueChanged
    End Sub

    Protected Overrides Sub OnUnsubscribeControlEvents(ByVal control As System.Windows.Forms.Control)
        MyBase.OnUnsubscribeControlEvents(control)

        Dim valueNumericUpDownControl As NumericUpDown = CType(control, NumericUpDown)
        RemoveHandler valueNumericUpDownControl.ValueChanged, AddressOf NumericUpDownControl_ValueChanged
    End Sub

    Public Event ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Private Sub NumericUpDownControl_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        RaiseEvent ValueChanged(sender, e)
    End Sub
End Class
While I Inherited from Windows.Forms.ToolStripControlHost it it acts more like its base control is a NumericUpDown rather than a ToolStripControlHost. Was this just a unique situation do to it being a ToolStripControlHost?

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Just incase someone runs across this looking for help in my instance the control was an ActiveX Control. AxImp.Exe comes with the SDK and it will automatically create a wrapper for your dll/ocx file and you can have it out the code in c# as well. This can then be used as is or converted to vb.net and used.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top