New to c#, how to add user control?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: New to c#, how to add user control?

  1. #1
    Join Date
    Feb 2001
    Posts
    2,455

    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

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    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...
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Feb 2001
    Posts
    2,455

    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

  4. #4
    Join Date
    Jan 2007
    Posts
    491

    Re: New to c#, how to add user control?

    Did you open an empty project, or a windows application?

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    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....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    Feb 2001
    Posts
    2,455

    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

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: New to c#, how to add user control?

    Clean, Zip and Post your project is you are still having problems...
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #8
    Join Date
    Feb 2001
    Posts
    2,455

    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
    Attached Files Attached Files

  9. #9
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    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....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  10. #10
    Join Date
    Feb 2001
    Posts
    2,455

    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

  11. #11
    Join Date
    Feb 2001
    Posts
    2,455

    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

  12. #12
    Join Date
    Jan 2007
    Posts
    491

    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.

  13. #13
    Join Date
    Feb 2001
    Posts
    2,455

    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

  14. #14
    Join Date
    May 2000
    Location
    Porsgrunn, Telemark in Norway!
    Posts
    292

    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!
    Last edited by Large; May 6th, 2007 at 01:14 PM. Reason: New updates added!
    ==========================
    Lars Werner aka Large
    http://lars.werner.no/
    ==========================

  15. #15
    Join Date
    May 2000
    Location
    Porsgrunn, Telemark in Norway!
    Posts
    292

    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
    ==========================
    Lars Werner aka Large
    http://lars.werner.no/
    ==========================

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


HTML5 Development Center