david.healed
david.healed

Reputation: 1309

How to put extended WinForms Control on ToolBox

I plan to add functionalities to TextBox with the following:

   public class TextBoxExt : TextBox  
    {
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            base.OnKeyPress(e);
        }

    }

The question is how can we use this TextBoxExt? Is there anyway to get this class onto the ToolBox so that we can just drag and drop it onto the form? If not, what is the best way to use the TextBoxExt?

Upvotes: 0

Views: 810

Answers (3)

sankar
sankar

Reputation: 1726

There is an another simple option to add a control into Toolbox is,

  1. Create a new toolbox tab in the VS Toolbox. Say for e.g. "My Own Control".
  2. Drag the assembly which has your control into the newly created tab and drop it.
  3. You can see your control added in your Toolbox.

Main advantage of this method is, if you have more than a control in your single assembly, you do not need to search in the Add Components dialog and choose them. VS will do it for you and will add all those automatically in Toolbox.

Hope this helps.

Upvotes: 1

Jeff Donnici
Jeff Donnici

Reputation: 2738

I believe there are a couple of ways to get your control to appear in the toolbox:

  1. The project it's in must be included in your open solution and the project must have been compiled/built into an assembly. This is the route to go if you're working on the control and a project that uses the control at the same time (e.g., building the solution will also re-build the control's project).

  2. You can right-click the toolbox to add new items... in the resulting dialog, you can browse to the assembly containing the control and add it that way (or add it to the GAC, in which case you can pick it right from the list without browsing). This is the route to go if the project containing your control won't be a part of your solution and you're dealing only with the compiled DLL (e.g., building the solution doesn't re-build the control's project).

Upvotes: 1

MusiGenesis
MusiGenesis

Reputation: 75296

Just compile your application - TextBoxExt should then show up in your Toolbox (you'll see it at the top, whenever you have a form designer open), and you can drag it onto your form.

The key here is probably to have a form designer open - otherwise, you won't see your custom user control in the toolbox.

Upvotes: 0

Related Questions