Question

I am working on a WinForm Application. The Form has many fields/components but is poorly built. for example a field is used as user name on one case and used as folder path on the other case. Code is quite poorly maintaned.

Is is possible that when i run the application and GUI appears, i can use a tool like 'spy++' which can show me 'names' of the components (not ids). For instance the name of a button or name of a label.

Or if i can use SPY++ for 'names' please tell me?

Was it helpful?

Solution

I would solve the problem by adding a ToolTip control to your form and iterating over each control and adding a Tool Tip message to each control that is the name of the control.

First, add a ToolTip object to your form (from the Tools section of the designer.) You can rename it, but for the sake of my demo, I left it as the default name toolTip1.

Next, add a method similar to the one I'm posting below to the code page of your form. (I'm assuming this is for C# but the code is simple and can easily be modified for VB or C++).

public void AddNameToToolTip(Control c)
{
    toolTip1.SetToolTip(c, c.Name);
    foreach (Control child in c.Controls) AddNameToToolTip(child);
}

Finally, from within the Form constructor, add the following line of code after the call to InitializeComponent().

AddNameToToolTip(this);

This will add a ToolTip message to each control in your form. All you should have to do is hover your mouse over each control and the ToolTip will pop up a message after a second or two displaying the name of the underlying control.

Alternatively, you can recursively adding a MouseHover event to each control and when the event is fired, write the name of the control to the debugger. This would also work if you are already using a ToolTip control within your form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top