简体   繁体   中英

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

  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.

如果您正在按提示查找面板,则表明您的应用程序中存在某些设计错误的信号……但是,这是解决方法

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM