|
Re: Where is my User Control: msg#00325windows.devel.dotnet.winforms
No, you can just use the control directly. A UserControl is, at the end of the day, just a class. A project doesn't need a reference to itself in order to use the classes it defines. So it's no different for controls. There's a different question which sometimes arises: How do I get Visual Studio .NET to let me add my control to my form? That's an entirely different question - this is a question of what VS.NET does for you by default as far as drag and drop is concerned. (So this is a Forms Designer thing, rather than a VS.NET project system thing. Project references are a part of the latter, and have no direct influence on the former. Although the reverse is not true - the Forms Designer will sometimes add project references for you.) Sometimes VS.NET will add the controls you have written to the Toolbox, sometimes it won't. If your control is a custom control (rather than a user control), then I don't think it ever appears in the Toolbox until you add it manually. For UserControls, they *normally* appear in the "My User Controls" section of the Toolbox. But sometimes they don't, and I'm not entirely sure why. (Your project needs to have been built for them to appear here though. So it might be worth closing the Form Designer, rebuilding the project, and reopening the Form Designer to see if the user control is now available in the My User Controls tab. That sometimes works.) For the cases where your controls don't show up in the toolbox (either because they're not user controls or because they just didn't appear) you have two options. You can just add code to use them directly. Many's the time I've just dropped some other control type onto the form and then done a search and replace to replace it with my control type. (Use the fully-qualified name including the namespace when you do this.) Once you've done that, when you go back to the design view, your control will now be on the form. Although it might have a size of (0,0), which you'll need to fix... (Your project will need to be built for this to work by the way - VS.NET needs a built copy of the control to host it in the designer.) The other approach is to add your library to the Toolbox. I usually just drag the DLL in directly from a Windows Explorer window onto the Toolbox because that tends to be faster than messing around with the customization dialogs. But you can just right click on a toolbox tab and choose Add/Remove Items... - if you then browse for your control library with the Browse... button on the .NET Framework Components tab, you can add it to the toolbox. Once it's on the toolbox, drag it onto your form like you would any other control. -- Ian Griffiths - DevelopMentor http://www.interact-sw.co.uk/iangblog/ > -----Original Message----- > From: Richard Heintze > > I need a dialog box with a user control. Since I am > sick of C++ I create a new sub project as a Class > Library. > > In this class Library I add a windows form and a user > control. When I had previously defined controls they > were in a different sub-project. > > Now, however, my user control is in the same > sub-project as the dialog that is going to use it. How > do I put my control in the dialog box? Does the sub > project need to have a reference added to itself? |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Accelerator Keys: 00325, Shawn A. Van Ness |
|---|---|
| Next by Date: | Re: Where is my User Control: 00325, Fabian Schmied |
| Previous by Thread: | Re: How to Use Versioningi: 00325, Andrew Dunn |
| Next by Thread: | Re: Where is my User Control: 00325, Fabian Schmied |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |