yogeshkmrsoni
yogeshkmrsoni

Reputation: 315

How to find a control from tooltip

IDE: VS 2010, c# .net 4.0, winforms

I have a Form form1, and it is having panels p1 p2 p3, having assigned tooltipText "pan1", "pan2", "pan3" respectively.

I know we can search control in a form using

Control[] c= this.controls.find("p1", true);  

But Is there any way to find control from toolTip text,

//example Control[] c1 = this.control.findByToolTip("toolTipText",true);  

I know we can map this using switch case but is there any easier way..?

Upvotes: 2

Views: 417

Answers (2)

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50712

If you are looking for panel by tooltip, it is a signal that something is designed wrong in your application... but however here is how to do it

  var c = this.Controls.OfType<Control>().Where(p => toolTipHCP.GetToolTip(p) == "toolTipText");

Upvotes: 2

Marton
Marton

Reputation: 831

  1. Create a collection of all the tooltip controls.
  2. Search in this collection.

Looping through all the controls and trying to typecast each of them would be a horrible solution.

Also, your design is probably flawed. I can't think of many scenarios where identifying a control by its contents is justified. It's usually the other way around.

Upvotes: 1

Related Questions