Groups | Blog | Home
all groups > visual studio .net ide > january 2004 >

visual studio .net ide : How to: get all of my controls to appear on My User Controls?


J.Marsch
1/27/2004 5:18:33 PM
I'm trying to get the My User Controls tab to work for me.
(VS.Net 2003, Winform controls in C#)

Here's my problem, I'm building out a number of controls (a lot right now,
because I'm doing prototyping/proof of concept work)

If I inherit from UserControl, the control automagically appears in the My
User Controls tab. If I inherit from any other class, it doesn't. Now, I
can manually add the controls to the tool bar, but it's painful. If I add
one control, I have to browse to the dll, and add it. This causes all of
the controls in the class lib to be re-added (so I have dups).

The My User Controls behavior (or something like it, where controls are
automatically added to the toolbar) is what I'm after right now. Is there
any way to do that with a non-usercontrol descendant?

timhuang NO[at]SPAM online.microsoft.com
1/28/2004 6:04:41 AM
Hello,

Thanks for your post. As I understand, the problem you are facing is that a
control which is not inherited from UserControl is not listed in the "My
User Controls" Toolbox. Please correct me if there is any misunderstanding.
I tested on my side, however, I am not able to reproduce the problem on my
side. The following is what I did:

1. Create a "Windows Control Library" project.
2. Build the project.
3. Add an "Inherited User Control" (UserControl2) which derived from
UserControl1.
4. Add an "User Control" (UserControl3), modify the code to let it
inherited from TextBox and comment out the code relating to
UserControl3_Load.
public class UserControl3 : System.Windows.Forms.TextBox
5. Build the project.
6. Add a Windows Form to the project, the UserControl1, UserControl2 and
UserControl3 are listed in "My User Controls" and I am able to add them to
the Form.

Please check it on my side. I look forward to your result.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
J.Marsch
1/28/2004 12:21:44 PM
Tian:

Thank you for your response. Your understanding is absolutely correct, but
if you alter your steps just slightly, you'll see my problem.

Try this:

1. Create a Windows Control Library project
2. Instead of adding an Inherited User Control, just add a class
3. Make the class inherit from the text box
4. No joy.


Now, I had previously noticed the behavior that you have outlined.
Originally, I thought that I would work around the problem by doing exactly
what you are doing in your steps: starting with a UserControl descendant
and then changing its inheritance. Unfortunately, that doesn't seem to work
so well over time.

I find that while I am developing the control, there are certain actions
that I can do (sorry, haven't figured out which) that will cause VS.Net to
reevalute the controls in MyControls. When that happens, it "notices" that
some of the controls are no longer descending from UserControl, and they get
removed.

When that happens, if I go back and change them to descend from usercontrol,
and then I can get them to reappear on the toolbox. Then I can change them
back, and they remain on the toolbox -- for a while, until I do whatever it
is that causes VS.net to reevaluate them and remove them again.

When I began the project, and only had a couple of controls in the library;
it was only a minor annoyance. Now I have more controls, and it's becoming
gradually more painful.

I was hoping that perhaps there is an attribute or something that I can
temporarily apply to my controls to cause them to always be loaded into
MyControls. (or even some other toolbox page)

[quoted text, click to view]

J.Marsch
1/29/2004 9:14:22 AM
Thank you, Tian.

I appreciate your help with this issue. It is unfortunate that there is no
other way to make VS.net automatically pick up the controls.


[quoted text, click to view]

timhuang NO[at]SPAM online.microsoft.com
1/29/2004 9:54:19 AM
Hi,

Thanks for your feedback. I reproduced the problem on my side. After
further research on this issue, I now share the following information with
you:

Based on my experience and research, the information of "My User Controls"
Toolbox is stored in the solution's .SUO file. When we add a User Control,
the Visual Studio .NET IDE will add the corresponding entry in .SUO file so
that the controll will be displayed in the Toolbox.

If somehow VS .NET need to reevalute the controls, those controls that do
not derived from UserControl will not be added to "My User Controls"
Toolbox. To work around the problem, I suggest that you can manually add
all the controls to Toolbox by the following steps:

1. Open the project in VS .NET IDE.
2. Bring up the "My User Controls" Toolbox, right-click and choose
"Add/Remove Items".
3. In "Customize Toolbox", click Browse button to select your DLL.
4. Now that all the controls in your DLL are selected and checked. You can
deselect all those which are already listed in "My User Controls".

As far as I know, there is no other method to work around the problem.

Please feel free to let me know if any further is needed.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button