Solved

Custom Controls lose their name at runtime Spy++/Automation (C#.Net)

Posted on 2012-03-19
8
534 Views
Last Modified: 2012-06-22
I have various custom controls, such as Horizontal/vertical splitters, and other third party controls.  The problem is that Visual Studio's Spy++ and the White automation framework, are unable to obtain names from these components.

http://screencast.com/t/pctNZ94iwcW <-- Spy++ Screenshot, Selected component is a list box, which loses its name as well.

Can anyone tell me why they are missing?  And particularly, how to get them back?  perhaps there is a system setting/dev setting to retain it.  I have source project, and can alter the build if need be, though it would be best not to have to.
0
Comment
Question by:hpdvs2
  • 4
  • 3
8 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 37737859
Were the controls put on the form at design-time?...or run-time?
0
 
LVL 40
ID: 37738309
The Name is not automatic.

The Windows Form Editor generates code that fills in the Name property when you put a Control on the Form in design.

The same does not apply however when you add the controls through your code. This is probably what is happening there. Simply fill-in the Name property when you create the control through code.
0
 
LVL 8

Author Comment

by:hpdvs2
ID: 37739438
These are for components that are added at design time.  The all have names in the properties window.
0
 
LVL 8

Author Comment

by:hpdvs2
ID: 37739440
This even includes ListView, as the screen shot shows on the highlighted record in the image.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 40
ID: 37739497
I just ran Spy++.

It does not display the name of the controls, but their Text property. Controls in which the Text property is not set display an empty string.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 37739587
This ones amuses me (maybe not you), so I fooled around a bit.

If you explore Spy++, you will see Caption in a few places, such as for searching, but never Name. Caption was used in the pre-.NET times for Text that is displayed but not editable by the user. I do not remember Name as a property of the controls at that time. I think it was only as an indication for the compiler. Somebody still working in VB6 might verify.

There does not seem to be a Text property in a UserControl or a ListView, but there is one, because UserControl inherits from Control. It has simply been hidden (look in help, it has the BrowsableAttribute set to False) because the designer of the class thought that it was useless. You can set the Text property of your UserControl in code even if it does not appear in IntelliSense. You will have to foor around a bit because IntelliSense will automatically enter something else, but you can edit the line afterward to keep Text alone. The control is then "captioned" as you want in Spy++.
0
 
LVL 8

Author Comment

by:hpdvs2
ID: 37780150
The problem is that many of these custom controls are from third party vendors.  So I cannot edit them.
0
 
LVL 8

Author Closing Comment

by:hpdvs2
ID: 37980481
This has been out here for a while, and I have not found a better solution, It doesn't solve it the way I wanted, but it sounds like its just not possible in some general way.  The information just doesn't get translated along to the build.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now