WinForms.net: a control for one project only - winforms

I want to make a composite control which I could drag to form multiple times, but this control should reside in one project only. I do not like the idea of making a control, and installing it to be visible to all projects in a Visual Studio 2010 Toolbox.
So, I assumed that the UserControl is what I needed. I created one, but now can't drag it to a form or find it in the Toolbox.
Tools > Options > Windows Forms Designer > AutoToolboxPopulate is set to True.

I had to compile the project to make UserControl appear in the Toolbox.

Related

Missing Toolbox Items in VS 2013

I'm developing a WinForms application using Visual studio 2013. I have two user controls and 1 custom control in my project. Unfortunately for some reason they are not appearing in my toolbox at design. At one point they did briefly but disappeared and never returned. I have tried resetting the toolbox, checking the AutoPopulate option and made sure that my project is built. I've seen solutions about adding controls that exist in their own library but these exist within the same project. My classes also have a namespace and the ToolboxItem(True) attribute.
Thanks

How can I make Visual Studio 2010's "Add User Control" create a WPF control?

I have a class library that I created using the "Class Library" project template. If I right-click on this library in Solution Explorer and select "Add > User Control", Visual Studio adds a WinForms UserControl. That's not what I want -- I want "Add > User Control" to add a WPF user control.
I've already added references to the WPF assemblies (WindowsBase, PresentationFramework, and PresentationCore), and I already have some WPF UserControls in this library, and everything compiles. My library does not have references to the WinForms assemblies (System.Drawing and System.Windows.Forms). But apparently the proper references are not enough of a clue for Visual Studio, because when I try Add > User Control, it adds the WinForms references to my project, and then creates a WinForms UserControl.
I can add a WPF User Control to my WPF Application project, and then move it into my library. But that's a pain, and I'd rather have it work properly in the first place.
I think I'm probably missing some kind of arcane XML element in my .csproj file that tells Visual Studio which designer to use by default, and if I add the right XML element with the right cryptic GUID, it will start working properly. If I could create a new WPF Control Library, I could probably compare the two project files and figure this out. However, I'm using Visual C# Express, which doesn't have a template for a WPF Control Library project, so I'm out of luck there.
What do I need to do to my Class Library's .csproj file so that VS2010's Add > New User Control will add a WPF UserControl?
There are sub-projects class ids in the project file that affect the Visual Studio context menus and how the project behaves in general. The easiest thing to do is to recreate the project as a:
WPF User Control Library
instead of a "Class Library". It is possible if you already created the project to edit in the sub-project class ids by hand by opening the ".csproj" file in a text editor such as Visual Studio itself but its easy to cause more damage than you fix that way.
I believe but haven't test that another type of library will also work:
WPF Custom Control Library
which is intended to hold other types of controls than UserControl objects but being a WPF sub-project type the context menus also work correctly for the use case you are describing.
Edit:
For completeness, I've just tested how to manually add the sub-project GUIDS. Add this line to the first PropertyGroup in the .csproj file:
<PropertyGroup>
...
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
Not tested with Visual Studio Express.

How can I make a WPF custom control automatically appear in the Visual studio toolbox?

If I create a WPF user control, it appears automatically in the Visual Studio toolbox.
Is there a way to make other controls appear automatically in the Visual Studio toolbox?
Conversely, is there a way to hide a user control from the toolbox?
You can right click on the toolbox and select Choose Items... Then from there you will get a dialog that allows you to select which controls to show or hide.
Per comment below if you are trying to figure out how to do this for a Third Party that you are providing your control to check out this MSDN article that describes packaging your control:
http://msdn.microsoft.com/en-us/library/ms165358.aspx
Auto population is described here (at the end), but to summarize you can add DesignTimeVisible(false) to your UserControl to prevent it from being added to the Toolbox.
Your controls should be added just like your UserControls, assuming they meet the requirements at the end of the link above, which are:
To appear in the Auto-Population
Toolbox process a type must derive
from FrameworkElement and:
Are public and have a default public or internal constructor or are
internal and have either a default
public or internal constructor
Types deriving from Window or Page are ignored
FrameworkElements in other .exe projects are ignore
Internal classes will only be displayed when the active designer is
for an item in the same project
Friend Assemblies are not taken into account for Toolbox
Auto-Population
If you are building reusable controls (where your end-users will simply add a reference to your assembly), then you'd need to tell Visual Studio that it should load your controls into the Toolbox. There is a tutorial for WinForms controls on doing this here, but the concepts are the same. A VSIX installer tutorial can be found here.
A lot of the resources out there are for older versions of Visual Studio, but again the same concepts should apply. You simply need to update version information where appropriate.

How to create a control like Solution Explorer in Visual Studio?

I want to create control that seems and works like the Solution Explorer of Visual Studio.
I mean not the functionality of solution explorer, the control should be seems like that control. That means, server explorer, toolbox, error List,... All these controls will pop-out when we put mouse and pop-in when we leave. We can lock and unlock those controls also.
So can anyone help me, to get the solution for this problem.
Thanks!!!!!!!!!!!
I am assuming you are using C#/VB.NET for development. The dockpanel suite will provide a docking framework for an application. Basically in terms of dockpanel, it is the forms which can be docked on the application using drag and drop like visual studio.
So create a treeview control in the form and dock it to the parent. You can populate the treeview control based on file directories or any specific needs of your project. Please note in dockpanel you create a form by not inheriting from Form class but from DockContent class. Documentation will give you more insight of how to create applications. It has a good example along with the source code in which it simulates the all the visual studio panes. It also provides and option to save the position of various docks which can act as a user preference. For eg, you may like to position solution explorer on left side whereas i may want it on right side. this get stored in a conf file which gets read next time when you start the application.
Incase you using MFC, then visual studio 2008 SP1 provides you with docking framwork and within that use the treeview control.
XAML also provides a docking framework. But i am not sure, you need to verify.
Win32 API does not have any native docking framework.

Custom silverlight user controls do not appear in Blend Assets tab

I've created a control in blend (xaml and code behind), saved it, and rebuilt the entire project. Now, not only does this new control not appear in the Assets tab in blend, none of the other user controls i've created appear either. I've rebuilt several times, blown away the obj and bin directories and rebuilt again, to no avail. How do I get my user controls to appear in the Assets pane so I can use them in my project?
thanks
Blend: 3.0.1927.0
VS: 9.0.30729.4108 QFE
.NET: 3.5 SP1
Sweeney,
I don't have the specifics of your install environment or applications installed, but using what I have, I can create a custom user control in blend and compile, pull it from my assets library, and put it on my page. Here are my specs, maybe you can check to see if you're running a different version or such:
Microsoft Expression Blend 2 Service Pack 1 - Version 2.1.1760.0
Microsoft Visual Studio 2008 - Version 9.0.30729.1 SP
Microsoft .NET Framework - Version 3.5 SP1
Here is what I did to create my custom control:
Open Blend.
Create new project (File > New Project..., Then named my Silverlight 2 Application, and clicked OK.)
Create new UserControl (File > New Item..., Then named my UserControl, and clicked OK.)
Create something like a colored background and text so that the control can be seen.
Build the application.
Add my custom control to the Page.xaml file from the Asset Library. (This may be where you got tripped up, please see below).
Size my new control.
Final product:
Screen Shot http://img163.imageshack.us/img163/7554/finalproduct.jpg
Accessing Custom Controls in Asset Library
Click the Asset Library icon (left side by default): Asset Library http://img43.imageshack.us/img43/2198/assetlibrary.jpg
Click the Custom Controls tab (top of Asset Library window): Custom Controls http://img5.imageshack.us/img5/8915/clickcustomcontrols.jpg
Select your custom control: Custom Control http://img693.imageshack.us/img693/1684/customcontrol.jpg
Place them on your page to your hearts content.
I hope this helps you,
Thanks!

Resources