Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add user control to a form

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.

like image 822
Viva Avatar asked Mar 18 '13 07:03

Viva


People also ask

How do you add a control into a form?

Add the control by drawing Select the control by clicking on it. In your form, drag-select a region. The control will be placed to fit the size of the region you selected.

Which method is used to put the user control on the form?

After adding control in tool box you can drag and drop control in your form where you want to use this control. Its my user control you can make own user control according to own requirement. If you want to get the custom control selected value and selected text write this code.

What is a user control in Windows Forms?

A UserControl is a collection of controls placed together to be used in a certain way. For example you can place a GroupBox that contains Textbox's, Checkboxes, etc. This is useful when you have to place the same group of controls on/in multiple forms or tabs.

What is the difference between a user control and a form?

User controls are a way of making a custom, reusable component. A user control can contain other controls but must be hosted by a form. Windows forms are the container for controls, including user controls. While it contains many similar attributes as a user control, it's primary purpose is to host controls.


1 Answers

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.

like image 80
Mohammad Dehghan Avatar answered Sep 20 '22 07:09

Mohammad Dehghan