Inherit from a ComboBox control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Spurry Moses

    Inherit from a ComboBox control

    Hi,

    I'm converting a project from C++Builder to C# and I just need to copy my
    class design across. It's looking good so far. To stick with the design I
    want to inherit from a ComboBox control (ie MyComboBox). I don't need to
    do anything flash with it, just add a few properties and methods. I'd
    almost solved this while writing this post but I'll just confirm what I'm
    doing is OK.

    It was a bit awkward in Visual Studio because all of it's auto-generated
    ways of creating controls use them as containers. And the one obvious
    option that should have worked "Add inherited Control" failed looking for
    "built assemblies". It must not be solution to my problem, I guess ;-)

    Anyhow, to get my new control to show up in the toolbox, I have to "Add
    User Control" and then delete all the code generated by it and replace it
    with this.

    public class MyComboBox : System.Windows. Forms.ComboBox
    {
    public MyComboBox() {
    // TODO: Add any initialization after the InitializeCompo nent call
    }
    }

    From there it basically seems to work. The combo box shows, I can put it
    in the form and all seems well. Although I haven't tested it much yet. Is
    there anything I'm missing like some Painting events might get screwed if
    I don't add some method or anything?

    I'll be happy if this is it!

  • Claudio Grazioli

    #2
    Re: Inherit from a ComboBox control

    On Mon, 16 May 2005 18:14:59 +1000, Spurry Moses wrote:
    [color=blue]
    > Hi,
    >
    > I'm converting a project from C++Builder to C# and I just need to copy my
    > class design across. It's looking good so far. To stick with the design I
    > want to inherit from a ComboBox control (ie MyComboBox). I don't need to
    > do anything flash with it, just add a few properties and methods. I'd
    > almost solved this while writing this post but I'll just confirm what I'm
    > doing is OK.
    >
    > It was a bit awkward in Visual Studio because all of it's auto-generated
    > ways of creating controls use them as containers. And the one obvious
    > option that should have worked "Add inherited Control" failed looking for
    > "built assemblies". It must not be solution to my problem, I guess ;-)
    >
    > Anyhow, to get my new control to show up in the toolbox, I have to "Add
    > User Control" and then delete all the code generated by it and replace it
    > with this.
    >
    > public class MyComboBox : System.Windows. Forms.ComboBox
    > {
    > public MyComboBox() {
    > // TODO: Add any initialization after the InitializeCompo nent call
    > }
    > }
    >
    > From there it basically seems to work. The combo box shows, I can put it
    > in the form and all seems well. Although I haven't tested it much yet. Is
    > there anything I'm missing like some Painting events might get screwed if
    > I don't add some method or anything?
    >
    > I'll be happy if this is it![/color]

    I'd say that's it. You can inherit from a control exactly that way and just
    add methods/properties you need. Painting and everything is done by the
    parent control so no need to add anything special.

    --
    Claudio Grazioli
    Our website about our photography and travel. Enjoy our picture galleries from around the world or read our blog about travel and photography


    Comment

    Working...