简体   繁体   中英

Given a .net control, can I get the tooltip?

I have a .net control (ok, a lot of them). I can invoke methods on any given control, but cannot create new controls or access static methods of the classes I don't have controls for. I don't have access to any tooltip objects. Is there any way I can get the tooltip object for a given control?

(We're using a rather restricted test automation framework in Java to access controls on an application written in C#.net, is the background behind this odd query)

ETA: Maybe I didn't make myself clear. I'm not trying to set a tooltip, I'm trying to get the existing tooltip. And I can't create new controls so anything that includes new Foo() isn't going to work.

string text = toolTip1.GetToolTip(yourControl);

这为您提供了控件的工具提示上的文本。

It appears this is not possible. :( To get the tooltip for a control, I need access to the ToolTip class, which is fine if I'm programming the controls but otherwise not really exposed.

you can do it like this

System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.textBox1, "Hello");

Add a Popup Event. Below, the code is getting the value set for the tooltip and also displaying it an status textbox on the MDIForm.

    private void toolTip1_Popup(object sender, PopupEventArgs e)
    {
        Control TheControl = e.AssociatedControl;
        cls_Global.gf_MDIForm.DisplayMsg(this.toolTip1.GetToolTip(TheControl) + "");
    }

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