-
New to c#, how to add user control?
Ok, so I am very very new to c#. In fact just trying my first application. I created a new application that has a form. I created a new class derived from UserControl. How do I add the new control to my form?
Probably very elementary question but I couldn't find the answer on google.
Mike B
-
Re: New to c#, how to add user control?
Compile the application. It should appear in the toolbox, then just drag and drop like any other...
-
Re: New to c#, how to add user control?
Quote:
Originally Posted by TheCPUWizard
Compile the application. It should appear in the toolbox, then just drag and drop like any other...
Hmmm, well I built and rebuilt the application, and I don't see anything. Class is named PlanView, so a control named PlankView should be in the toolbox?
Mike B
-
Re: New to c#, how to add user control?
Did you open an empty project, or a windows application?
-
Re: New to c#, how to add user control?
Talikag brings up a good point. I was assuming that your UserControl was in the same solution as your form....
-
Re: New to c#, how to add user control?
Quote:
Originally Posted by TheCPUWizard
Talikag brings up a good point. I was assuming that your UserControl was in the same solution as your form....
Yes, the UserControl is in the same solution as the form.
1) I created a Windows Application
2) I created a new class derived from UserControl
3) I built the application.
Now I want to add that UserControl to the from1 created in step 1.
Hmmmm, let me try this again. I don't have much to redo. maybe 5 minutes work :)
Mike B
-
Re: New to c#, how to add user control?
Clean, Zip and Post your project is you are still having problems...
-
1 Attachment(s)
Re: New to c#, how to add user control?
Quote:
Originally Posted by TheCPUWizard
Clean, Zip and Post your project is you are still having problems...
Well, I must be doing something wrong or mis-understanding how to do it. Because I don't see any new "PlankView" control.
Thanks for you help, source is attached.
Steps I followed:
1) New Project
2) Renamed .cs file from Form1 to MainFrame.cs
3) Project/Add User Control
4) Specified "PlankView.cs" for name and selected "User Control" template.
5) Add OnPaint event handler for the control.
6) Compiled
Looked for a new control in the toolbox and nothing with the name PlankView.
Mike B
-
Re: New to c#, how to add user control?
Downloaded project, compiled, opened toolbox, and "PlankView" is shown under "BedPlan2k7 Components" in the toolbox, dragged it onto the form....
You MUST be missing something....
-
Re: New to c#, how to add user control?
Quote:
Originally Posted by TheCPUWizard
Downloaded project, compiled, opened toolbox, and "PlankView" is shown under "BedPlan2k7 Components" in the toolbox, dragged it onto the form....
You MUST be missing something....
LOL, I hate this, everytime I try something new..... I am using Visual Studio 2005 professional. I have closed and opened that project, I have compiled and recompiled that solution, and I don't get a "BedPlan2K7 Components" in my toolbox.
Arrrrggghhhhh....
:) Thanks
Mike B
-
Re: New to c#, how to add user control?
Quote:
Originally Posted by TheCPUWizard
Downloaded project, compiled, opened toolbox, and "PlankView" is shown under "BedPlan2k7 Components" in the toolbox, dragged it onto the form....
You MUST be missing something....
I even went as far as downloading that project myself, building the app, and still nothing.....
What could I be missing?
Mike B
-
Re: New to c#, how to add user control?
Did you open the "ToolBox" Window? If you didn't - do it, and drag the user controls & components to the form, if you did - just drag from the toolbox controls into the form. Or maybe the user controls doesn't appear there? Maybe you sould attach a printscreen. It might help.
-
Re: New to c#, how to add user control?
Quote:
Originally Posted by Talikag
Did you open the "ToolBox" Window? If you didn't - do it, and drag the user controls & components to the form, if you did - just drag from the toolbox controls into the form. Or maybe the user controls doesn't appear there? Maybe you sould attach a printscreen. It might help.
Yes, I have the toolbox open. I even went as far as opening and closing the toolbox several times. There is no "user controls and / or components" in my toolbox.
To tell you the truth, I was just doing this for learning purposes. I deleted the project, I will try again tomorrow and give you a print screen. I am confident it won't work then either. :)
Mike B
-
Re: New to c#, how to add user control?
Any luck with this? I have the exactly same problem. When I first setup the VS2005 I choosed C++ layout for menus and so on. Did you do the same?
Edit:
"Fix" found. Seems to be an error when you choose other profiles to work with (I used C++ style). Follow these steps to fix:
* Close the solution you have open
* Tools -> Import and export settings
* Select "Reset all settings" (Save your old settings if you like)
* Select "General Development settings"
Do the same all over again then select "Visual C# Development settings"
That worked for me, please let me know if it works for you to!
-
Re: New to c#, how to add user control?
Quote:
Originally Posted by petes1234
Look in the toolbox area again, and if you haven't done so expand the section labeled "All Windows Forms". Look on the bottom of that section for something that looks like a blue toothed gear. That may be your user control.
It seems to be a strange bug for me. Guess the IDE thingy ain't so great after all
-
Re: New to c#, how to add user control?
I have no idea if I did anything right or not, but try this just for grins:
- In your MainFrame.cs file add the line "PlankView pv = new PlankView();" after InitializeComponent();
- compile and run your app
- NOW look in the toolbox. Did the component appear?
Let me know if this helps.
-
Re: New to c#, how to add user control?
Quote:
Originally Posted by Large
It seems to be a strange bug for me. Guess the IDE thingy ain't so great after all
No, my post was wrong (buggy -- yeah, that's right!). Please ignore that post, but not my post immediately preceding this one. I have deleted the erroneous post.
/Pete
-
Re: New to c#, how to add user control?
Please take a look on the post: http://www.codeguru.com/forum/showpo...5&postcount=14
The problem is on every control you added. I just worked on getting the Officepanels (http://www.codeproject.com/useritems...007_Panels.asp) working here. The Tabbutten and Ribbonpanel did not show in the toolbox until I took full reset of the configuration.
So this is not a "random" problem. The toolbox did not work correctly when I choosed c++ layout insted of C# layout.
-
Re: New to c#, how to add user control?
Interesting. Thanks for pointing this out.
-
Re: New to c#, how to add user control?
It isn't necessary to reset the whole configuration.
Try this:
1) Close your solution
2) Tools->Options->"Windows Form Designer"
- find AutoToolboxPopulate property in Toolbox category and set 'true'
3) Open your solution.
Thanks,
Jordan