Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Control from scratch ?

Control from scratch ?

Scheduled Pinned Locked Moved C#
tutorialperformancequestion
18 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ _Q12_

    YES You got that right. And is for WinForm.(i'll edit my original post) thanks and sorry for omitting it.

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #9

    Okay, well if I were you then, I would start by looking to inherit from ContainerControl (that's what UserControl inherits from). Then, you need to evaluate whether or not you need the features that you get specifically from the UserControl (e.g. Border).

    Chill _Maxxx_
    CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

    _ 1 Reply Last reply
    0
    • _ _Q12_

      How to create a control from scratch? (for WinForm applications) NOT inherit/extend UserControl. I want to create something totally new. A good example is the timer control properties - i bet that is not an extension from Usercontrol. Something similar i need. { I just want to create(fromScratch),visualize and use a NEW control with its properties (and events). } For example: I want a Control named "Car" Properties: wheels,doors,windows,lights,sounds,color,name,class,subclass,etc Events: Speed,Stop, Accelerate,Brake,click, collide,touch, lightsOn,soundOn,noWheels,etc And nothing more than this ! Thanks.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #10

      Take a look at the inheritance hierarchy for System.Windows.Forms.Timer[^]. Now look at each upper level class, that should give you an idea of the amount of work ahead of you.

      Veni, vidi, abiit domum

      1 Reply Last reply
      0
      • _ _Q12_

        How to create a control from scratch? (for WinForm applications) NOT inherit/extend UserControl. I want to create something totally new. A good example is the timer control properties - i bet that is not an extension from Usercontrol. Something similar i need. { I just want to create(fromScratch),visualize and use a NEW control with its properties (and events). } For example: I want a Control named "Car" Properties: wheels,doors,windows,lights,sounds,color,name,class,subclass,etc Events: Speed,Stop, Accelerate,Brake,click, collide,touch, lightsOn,soundOn,noWheels,etc And nothing more than this ! Thanks.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #11

        Inherit from Control[^]; that's the correct base-class to inherit from when visualizing things. For non-visual components inherit from Component[^].

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        _ 1 Reply Last reply
        0
        • _ _Q12_

          How to create a control from scratch? (for WinForm applications) NOT inherit/extend UserControl. I want to create something totally new. A good example is the timer control properties - i bet that is not an extension from Usercontrol. Something similar i need. { I just want to create(fromScratch),visualize and use a NEW control with its properties (and events). } For example: I want a Control named "Car" Properties: wheels,doors,windows,lights,sounds,color,name,class,subclass,etc Events: Speed,Stop, Accelerate,Brake,click, collide,touch, lightsOn,soundOn,noWheels,etc And nothing more than this ! Thanks.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #12

          Eddy is right. If you want to build a control from scratch you inherit from either Control or Component. UserControl is normally used when you want to build a new control from a mash up of other controls, like a button and textbox.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          1 Reply Last reply
          0
          • L Lost User

            Inherit from Control[^]; that's the correct base-class to inherit from when visualizing things. For non-visual components inherit from Component[^].

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            _ Offline
            _ Offline
            _Q12_
            wrote on last edited by
            #13

            Ok, and if i choose from Control to inherit(it's easier), then how I hide the rest of the properties showing in my Properties window?

            L 1 Reply Last reply
            0
            • P Pete OHanlon

              Okay, well if I were you then, I would start by looking to inherit from ContainerControl (that's what UserControl inherits from). Then, you need to evaluate whether or not you need the features that you get specifically from the UserControl (e.g. Border).

              Chill _Maxxx_
              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              _ Offline
              _ Offline
              _Q12_
              wrote on last edited by
              #14

              Ok, and if i choose from Control to inherit(it's easier), then how I hide the rest of the properties showing in my Properties window?

              1 Reply Last reply
              0
              • _ _Q12_

                Ok, and if i choose from Control to inherit(it's easier), then how I hide the rest of the properties showing in my Properties window?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #15

                You don't; they're inherited and required for the correct working of a control. Without them, you can't call it a control. You can hide properties using a hack, but that's all it is - a hack. It doesn't mean that the properties aren't accessible.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                _ 1 Reply Last reply
                0
                • L Lost User

                  You don't; they're inherited and required for the correct working of a control. Without them, you can't call it a control. You can hide properties using a hack, but that's all it is - a hack. It doesn't mean that the properties aren't accessible.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  _ Offline
                  _ Offline
                  _Q12_
                  wrote on last edited by
                  #16

                  then, yes, i'm very interested on it- can you give me an example on how to do it? Please, and thanks.

                  L 1 Reply Last reply
                  0
                  • _ _Q12_

                    How to create a control from scratch? (for WinForm applications) NOT inherit/extend UserControl. I want to create something totally new. A good example is the timer control properties - i bet that is not an extension from Usercontrol. Something similar i need. { I just want to create(fromScratch),visualize and use a NEW control with its properties (and events). } For example: I want a Control named "Car" Properties: wheels,doors,windows,lights,sounds,color,name,class,subclass,etc Events: Speed,Stop, Accelerate,Brake,click, collide,touch, lightsOn,soundOn,noWheels,etc And nothing more than this ! Thanks.

                    _ Offline
                    _ Offline
                    _Q12_
                    wrote on last edited by
                    #17

                    + I have another problem = it seem that i can not add new events- well,working events. here is what i did so far:

                    public event EventHandler textchange2;

                    If i insert only this line in my "Car" control object , it will appear in events list when the new control will be added. The rest of the code is over my head... >>>

                    protected virtual void ontextchange2(EventArgs e)
                    {
                    EventHandler handler = textchange2;
                    if (handler != null) handler(this, new EventArgs());
                    }

                    1 Reply Last reply
                    0
                    • _ _Q12_

                      then, yes, i'm very interested on it- can you give me an example on how to do it? Please, and thanks.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #18

                      http://stackoverflow.com/questions/1875401/how-to-hide-an-inherited-property-in-a-class-without-modifying-the-inherited-cla/4892913#4892913[^] FWIW; it's a "worst" practice. It does not add any functionality, does not add any value, and only introduces more code - code that needs maintenance, could contain bugs, and which is only used by the programmer that's using your component.

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups