add user control to a form
Asked Answered
G

2

39

I have created a user control with a TextBox and two Buttons, but I haven't created events, just I place them to user control. When I want to add the user control to my form it says:

Cannot move Task_control.cs. The destination folder is the same as the source folder.

I can't understand why.

Grouchy answered 18/3, 2013 at 7:18 Comment(3)
In Custom control you will specify event.Boodle
How are you trying to add the user control to the form? Are you dragging it from Solution Explorer to the form?!Storytelling
Yes. I drag it because it doesn't appear in toolbox.Grouchy
S
87

After creating your user control, you should build the project (F6 or Ctrl+Shift+B).

Then Visual Studio automatically adds the control to the Toolbox. You should drag the control from the Toolbox (Ctrl+Alt+X) to the form.

If after successfully building the project, the control is not on the Toolbox, make sure that you have Automatically Populate Toolbox set to true: Go to Tools->Options, select Windows Forms Designer node, and set Automatically Populate Toolbox to true.


You can also manually add your user control to the toolbox (if "Automatically Populate Toolbox" is not set, and you don't want to set it!). It is highly recommended that you create an additional Tab on the Toolbox for your specific user controls: Right click on an empty area of the Toolbox and click Add Tab, then give the new tab a name.

Now build the project, right click on an empty area on the toolbox (of course, in tab you already created, or in the "General" tab), and select Choose Items:

Adding controls to the Toolbox

Wait a few seconds (or minutes) for the dialog to be ready, then click Browse and select your assembly. All of your user controls are now in the list. Select the ones you want to add to the Toolbox and click OK.

Storytelling answered 18/3, 2013 at 7:34 Comment(0)
L
0

After creating your user control, you should build the project from the Solution Explorer. Click on your project name and click build, If it doesn't work rebuild it again enter image description here

Lipography answered 12/10, 2019 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.