locked
formatting tool tip text RRS feed

  • Question

  • I'm trying to use tool tips in a non-traditional way.  Basically, I've got a control whose value represents a sum of some numbers.  In the tool tip I'd like to show the details of these individual items.  This all works, however, the item details have 3 parts (a date, a name, and an amount), which ideally I'd like to line horizontally up so it's easier to read.  I'm formatting the text to do this, but unfortunately the default tool tip is not a fixed sized font, so the items still don't line up.

    Is there some other way to format the string to get a guaranteed pixel width instead of character width? Is there a way to change the tool tip font w/o disabling the visual styles?
    Tuesday, April 21, 2009 1:53 AM

Answers

  • You can change a tooltip font - described here .
    • Proposed as answer by codevanced Tuesday, April 21, 2009 10:55 PM
    • Marked as answer by DP2308 Wednesday, April 22, 2009 2:05 PM
    Tuesday, April 21, 2009 10:55 PM

All replies

  • You can do it this way
    toolTip1.SetToolTip(button1, "Date : " + Datevalue + "\r\nName : " + NameValue + "\r\nAmount : " + AmountValue);

    kaymaf

     


    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, April 21, 2009 4:28 AM
  • I'm looking for all 3 items on the same line.  For example, I'd like to see something like

    04/21/2009 ShortItemName               $10.00
    04/21/2009 AVeryVeryLongItemName $20.00

    This forum is actually a great example since it's not using a fixed size font.  As a result, even manually typing I can't align the amounts on the two lines above.
    Tuesday, April 21, 2009 3:17 PM
  • try this
    t.SetToolTip(button1, "04/21/2009" + " " + "ShortItemName" + " " + "$10.00");
    kaymaf

    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, April 21, 2009 3:47 PM
  • you can also use string format, then pass the value to settooltip
    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, April 21, 2009 3:48 PM
  • I am using string format.  But since the default font for tool tips is not a fixed size font, the sizes of name part of the string are different sizes depending on which characters make up the name.  So I'm looking for a way to change the tool tip font, or a more explicit way to specify formatting that doesn't depending on the size of the font.
    Tuesday, April 21, 2009 8:22 PM
  • Does /t work to use a tab?
    www.insteptech.com
    • Proposed as answer by DeborahKMVP Wednesday, April 22, 2009 5:19 AM
    Tuesday, April 21, 2009 9:21 PM
  • try this agian,

    t.SetToolTip(button2,

    "04/21/2009"+" "+"ShortItemName"+" "+"$10.00");
    t.SetToolTip(Button1,
    "04/21/2009" + "\t" + "ShortItemName" + "\t" + "$10.00");

    i know it easy to do in vb, try to see if there is any equivalent to this line below in C# except \t .
    VB: t.SetToolTip(Button1, "04/21/2009" + Space(1) + "ShortItemName" + Space(2) + "$10.00")
    kaymaf

     

     


    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, April 21, 2009 9:41 PM
  • I guess the tabs will work if the difference in the name lengths is less than the width of the tab.  I suppose I can just try to get the lengths of all of the names, then add 1 tab to the longest one and 1 + n tabs to the shorter ones depending on how many tab widths they are shorter than the longest.  I hoping there was something in the format that would make this easier, but if not it shouldn't be too complicated.
    Tuesday, April 21, 2009 10:00 PM
  • Do want to measure the lenght of each names? let me know
    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, April 21, 2009 10:03 PM
  • you can use this to get width of the string, you can use any control to get font because tooltip has default font

    public float MygetWidthTextSize(string StringText, Control cont) 
    { 
        Graphics g = cont.CreateGraphics; 
        Font ft = cont.Font; 
        float contTextSize = 0; 
        contTextSize = g.MeasureString(StringText, ft).Width; 
        g.Dispose(); 
        return contTextSize; 
    } 
    

    kaymaf

     


    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, April 21, 2009 10:20 PM
  • You can change a tooltip font - described here .
    • Proposed as answer by codevanced Tuesday, April 21, 2009 10:55 PM
    • Marked as answer by DP2308 Wednesday, April 22, 2009 2:05 PM
    Tuesday, April 21, 2009 10:55 PM
  • This is helpful. Thank you.  Is it possible to use this value directly in the string format somehow (i.e. can you specify the offset in pixels instead of characters)?  If not, no big deal.  Just thought I'd ask.
    Tuesday, April 21, 2009 10:57 PM
  • I was looking for ways to align Tooltip (multiline). 
    DP2308, Thank you for sharing your workaround.

    I think /t tab width can vary from machine to machine (if I'm not wrong).

    How do I get the width of the tab string programatically? Any thoughts?

    Thanks
    Monday, May 11, 2009 10:00 PM
  • I was looking for ways to align Tooltip (multiline). 
    DP2308, Thank you for sharing your workaround.

    I think /t tab width can vary from machine to machine (if I'm not wrong).

    How do I get the width of the tab string programatically? Any thoughts?

    Thanks

        You are reply to thread that already marked, you can start new thread
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, May 12, 2009 12:07 AM