leora
leora

Reputation: 196489

Multiline tooltipText

I am trying to have a tooltip on multiple lines. how do i do this?

Upvotes: 30

Views: 29895

Answers (6)

Kristian Sik
Kristian Sik

Reputation: 163

Place this 
 where you want to break the line (in designer).

Upvotes: 1

Akhrib Farouk
Akhrib Farouk

Reputation: 1

1- First of all you need to set event on your tooltip: goto your tooltip events, double click on Draw

NB: even if your control is not a textbox but this will work for all controls because this option is just a behavior.

-Make your event look like this:

    private void tooltip1_Draw(object sender, DrawToolTipEventArgs e)
    {
        e.DrawBackground();
        e.DrawBorder();
        e.DrawText(TextFormatFlags.TextBoxControl);
    }

2- Goback to tooltip properties and change "OwnerDraw" to true.

3- Now you are able to call your event from anywhere and you can customize forecolor and backcolor now as you like, and this is a simple tip : in this example:i have a tooltip named:"tooltip1" and Textbox named:"textbox22"

  private void textBox22_MouseHover(object sender, EventArgs e)
    {
        tooltip1.ForeColor = Color.lime;
        tooltip1.BackColor = Color.black;
        tooltip1.Show("Path to a file\nExample:\n--check \"C:\\SomeDirectory\\Somefile.exe\"\nNB:\nWe don't check for the validity", this.textBox22);
    }

and you will see a semiFullcustomize Tooltip with multiline text by the "\n" which is equivalent to "Environment.NewLine", and the text should be lime text on black background.

Upvotes: 0

flodis
flodis

Reputation: 1221

To avoid escaping special characters as newline, easiest is to use String.Format() syntax to insert linebreaks in one or multiple places. In this case the last parameter {3}, Environment.NewLine, is inserted in two locations.

tipText = String.Format("{0:HH:mm}{3}{1:0.00}{3}{2}", ADateTime, ADouble, AString, Environment.NewLine);

Upvotes: 0

Aaron B.
Aaron B.

Reputation: 1835

Just for reference, in C++, one can simply add the "\n" tag directly in static text.

Upvotes: 1

JaredPar
JaredPar

Reputation: 754705

Put a newline (use Environment.NewLine) into the actual tooltip text.

Upvotes: 36

You can enter a newline in the designer also (for static-text only, obviously) by clicking the dropdown arrow near the tooltip property-box, and hitting enter where you want the newline.

Upvotes: 40

Related Questions