Solved

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

Posted on 2012-03-19
8
538 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

777 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