5

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.

Yamikuronue
  • 746
  • 8
  • 37
  • 7
    The underlying Windows message is TTM_GETTOOLINFO. You'll get a TOOLINFO filled if the control supports a tooltip. There's no control method for that. – Hans Passant Apr 19 '12 at 20:13
  • @HansPassant Your comment is more helpful than any of the current answers. I'm intrigued. – Yamikuronue Apr 19 '12 at 20:35
  • I understand the question well enough to know I can't answer it. No idea what a "restricted test automation framework in Java" can do. – Hans Passant Apr 19 '12 at 21:20
  • @HansPassant Invoke methods and fetch properties on controls :( I think the answer is "you can't do what you want to do here", so I'll have to dig deeper into alternate methods. – Yamikuronue Apr 20 '12 at 12:13

4 Answers4

4
string text = toolTip1.GetToolTip(yourControl);

This gives you the text on the tooltip for yourControl.

meetjaydeep
  • 1,752
  • 4
  • 25
  • 39
2

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.

Yamikuronue
  • 746
  • 8
  • 37
1

you can do it like this

System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.textBox1, "Hello");
Al Katawazi
  • 7,192
  • 6
  • 26
  • 39
-1

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) + "");
    }