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.
  • _ Offline
    _ Offline
    _Q12_
    wrote on last edited by
    #1

    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.

    C M P L D 7 Replies 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.

      C Offline
      C Offline
      Chris Quinn
      wrote on last edited by
      #2

      Does the NoWheels event cause them to drop off, like something out of Wacky Races?

      ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

      _ 2 Replies Last reply
      0
      • C Chris Quinn

        Does the NoWheels event cause them to drop off, like something out of Wacky Races?

        ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

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

        when are all over worn/overused, maybe? :) idontknow. :)

        1 Reply Last reply
        0
        • C Chris Quinn

          Does the NoWheels event cause them to drop off, like something out of Wacky Races?

          ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

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

          any idea on how can be achieved this high level of programming stuff? Any simple example --rudimentary-- like a snippet ? What i manage to create until now: But is a UserControl extension.

          public partial class Car : UserControl
          {
          public Car()
          {
          InitializeComponent();
          CarLoad();
          }
          public void CarLoad()
          {
          Life = 50;
          Wheels = 4;
          PaintColor = BackColor = Color.Aqua;
          this.Size = new Size(20, 20);
          }

              \[DefaultValue(50)\]
              \[Description("...")\]
              public int Life { set; get; }
              \[DefaultValue(4)\]
              public int Wheels { set; get; }
          
              \[DefaultValue(typeof(Color), "Aqua ")\]//"255, 0, 0"?
              public Color PaintColor { set; get; }
          
          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.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            What you are describing is an object not a control. A control implies that it is a user interface element whereas an object has a bunch of properties and events.

            Never underestimate the power of human stupidity RAH

            _ 1 Reply Last reply
            0
            • M Mycroft Holmes

              What you are describing is an object not a control. A control implies that it is a user interface element whereas an object has a bunch of properties and events.

              Never underestimate the power of human stupidity RAH

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

              But i want to see it in my controls list(also). (Like a derivation from UserControl one) in [Objects Components] control list panel.

              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.

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

                So basically you want to rewrite all the infrastructure that UserControl puts in place for hosting in Visual Studio, on the designer, display at runtime, etc? Have I got that correct? Well, one of the first problems you're going to face getting an answer is that you haven't specified which platform this is for. Is it WinForms? WPF? Silverlight? ASP.NET?

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

                _ 1 Reply Last reply
                0
                • P Pete OHanlon

                  So basically you want to rewrite all the infrastructure that UserControl puts in place for hosting in Visual Studio, on the designer, display at runtime, etc? Have I got that correct? Well, one of the first problems you're going to face getting an answer is that you haven't specified which platform this is for. Is it WinForms? WPF? Silverlight? ASP.NET?

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

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

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

                  P 1 Reply Last reply
                  0
                  • _ _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