Results 1 to 7 of 7

Thread: [RESOLVED] Creating and building custom controls in 2005

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Resolved [RESOLVED] Creating and building custom controls in 2005

    Can someone point me in the direction of a good tutorial on creating and building custom controls that can be added to the Toolbox?

    Thanks in advance for the help.
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Creating and building custom controls in 2005

    There is no general tutorial. It all depends on what you want your control to do.

    In general though, there are two types:
    - UserControls.
    - Custom controls.

    UserControls are a type of 'container' you can add controls to, which then shows up in the toolbox as a single control. Think of a TextBox with a ToolStrip above it, or something like that.

    Custom controls are simply classes that inherit from some other control and extend their behavior. To inherit from some control just use the Inherits statement. For example, to inherit a Button you can do
    Code:
    Public Class CustomButton
       Inherits Button
    
    End Class
    Now, the class CustomButton will behave exactly like an ordinary button (even though it's only 3 lines of code!). You can now start extending it by adding methods or properties, or by overriding existing properties (using the Overrides statement; just type 'Overrides' and use the Intellisense to see what you can do).


    EDIT
    I should have added... In order for a class to appear in the Toolbox, all that is required is that it implements IComponent, either directly or indirectly. Since both the UserControl and the Control class (from which, in turn, all other controls such as buttons inherit) implement IComponent, they will all appear in your toolbox. The only thing you need to do is Build your solution successfully.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Re: Creating and building custom controls in 2005

    Nick, thanks, but I'm really just looking for a tutorial on the process to go through to build it and use it from the toolbox. I'm familiar with extending properties of a control within a user created class in my project. Just don't know how to go from that to being able to add it to the toolbox so that I can drop it into a projects form from there and re-use it in other projects.
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

  4. #4
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Creating and building custom controls in 2005

    If you are already familiar with extending classes, then all you need to do is extend an existing Control (or inherit Control directly, or implement IComponent directly) and then build your solution. To build, just go to the Build menu and click Build Then, if the build succeeded, the control should show up at the top of the toolbox automatically (as long as you are in the same project of course).

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Re: Creating and building custom controls in 2005

    Thanks Nick.
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Re: [RESOLVED] Creating and building custom controls in 2005

    Ok, now I'm really feeling dumb. I've always set up a custom control by creating a class and put them on the form using code from the form.

    After trying to resolve this I finally figured out that somewhere along the line I had Tools>Options Windows Forms Designer AutoToolboxPopulate set to False!

    Very frustrating. Thanks again for your help.
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

  7. #7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width