Question about inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Rahav

    #1

    Question about inheritance

    Hi,

    I use VB .NET 2003 and I want to create a new UserControl that will function
    as a "smart" combobox that handles few events automatically (such as
    auto-complete, etc.) in addition to the regular combobox events.
    I created a new class that inherits from: System.Windows. Forms.ComboBox.
    I added the some code to the events in the new combobox (in the UserControl
    project) and add the control to a win-form in a different project.
    The problem is that the enevts I added don't run... When I tried to
    understand why, I found that the SmartCombobox control in the win-form
    project has its own events (as regular combobox), and what is being run is
    the "local" events and not the code I added to the events in the new class.
    What should I do in order to run the code in the new control automatically?

    Thanks!
    Tom.


  • JasonS

    #2
    Re: Question about inheritance

    On Thu, 24 Nov 2005 16:36:14 +0200, Tom Rahav wrote:
    [color=blue]
    > Hi,
    >
    > I use VB .NET 2003 and I want to create a new UserControl that will function
    > as a "smart" combobox that handles few events automatically (such as
    > auto-complete, etc.) in addition to the regular combobox events.
    > I created a new class that inherits from: System.Windows. Forms.ComboBox.
    > I added the some code to the events in the new combobox (in the UserControl
    > project) and add the control to a win-form in a different project.
    > The problem is that the enevts I added don't run... When I tried to
    > understand why, I found that the SmartCombobox control in the win-form
    > project has its own events (as regular combobox), and what is being run is
    > the "local" events and not the code I added to the events in the new class.
    > What should I do in order to run the code in the new control automatically?
    >
    > Thanks!
    > Tom.[/color]

    Don't try and capture the events in your subclass, but override the On...
    methods.
    For example:
    Public Class Form1
    Private Sub ComboBox1_Click (ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles ComboBox1.Click
    MessageBox.Show ("Hi!")
    End Sub
    End Class

    Public Class myCombo
    Inherits Windows.Forms.C omboBox

    Public Sub myCombo()
    End Sub

    Protected Overrides Sub OnClick(ByVal e As System.EventArg s)
    MessageBox.Show ("Ho")
    MyBase.OnClick( e)
    End Sub

    End Class

    This will display a message box before calling your client app's click
    event.

    Cheers,
    Jason

    Comment

    Working...