?
Solved

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

Posted on 2012-03-19
8
Medium Priority
?
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 86

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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 
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 1000 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

764 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