views:

116

answers:

3

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?

A: 

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.

MusiGenesis
If that fails, you can add it manually. Follow the steps here, but you wont be looking for COM and you'll pick your DLL. http://www.activesoundrecorder.com/help/asrec_000066.htm
rie819
+1  A: 

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).

Jeff Donnici
A: 

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.

sankar