Click here to Skip to main content
13,003,930 members (101,575 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I made a Windows Forms application and displaying details of current project in the Titlebar of the main form. When the text is long it is getting truncated. How to display the full text in a tooltip when the cursor is hovered on the title bar of the main form?
Posted 10-Mar-12 22:25pm
VJ Reddy38.8K
patar sii miaw 11-Mar-12 4:34am
you can set the tooltip on from the game.
vjreddy 11-Mar-12 5:57am
I could not under stand what you want to say. Can you please elaborate.
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

<This is too long for a comment.>

The TitleBar Text of a Form is not intended to be a feedback mechanism for presenting information, and the idea of truncated Text, in the TitleBar, which then, must, somehow, be expanded: is not good UI design in general, and will be quite confusing to users of your application.

The idea of a ToolTip appearing that shows the full-text of a TitleBar (where the TitleBar text is so long that it is truncated by the width of the Form):

Whether it's your own idea, or a requirement for work, or whatever, is:

A very bad idea; it violates the whole "visual tradition" of Windows' applications' "look and feel" (at least until we get to Modern/Metro, where all our previous MS UI experience is thrown under the bus) as expressed in the Microsoft Windows Style guides.

The TitleBar text of a Form should display text that expresses what a Form is for, or what it does, or the name the user gave it when they created it:

In the case of multiple, identical Forms, created at run-time: perhaps Form title-text can be followed by an identifying number, to help users keep track of which Form they are using.

Having the TitleBar title change its text during run-time, if that's what you are describing is going to happen when your application runs: is just bizarre.

Automatically scrolling text in a StatusBar is also strange, but, I have seen it done, and a StatusBar is, by design, one control used to present changing summary information.

Windows' users are socialized over years to certain expected visual style and behavior of applications, and their windows (although the game is about to change with Modern/Metro coming):

In general, you want to make it easy for a new user of your application to "leverage" what they already know in using your application:

For now, I strongly suggest you use traditional design ... unless, of course, you are writing a game in which case you can invent whatever weirdness you desire :)

Even within traditional design: you can create custom-shaped Forms, Forms that can be moved that don't have a title-bar, Forms that have custom title-bars:

CP is full of articles describing all kinds of Form modification techniques.

And, if you have Aero available, you can use "glass" and its other various Form decorations, or simulate them (until Win 8 comes, that is).

You have some interesting answers here, and, in the past, I coded-up a ToolTip that displays only when the mouse is over the TitleBar area (the non-client area) of a Form:

AlbertDC gives you a vague hint at how to do that below: it involves writing a WndProc, but there's a much better way to write that WndProc:

And, it is damn tricky to make a WndProc invoked PopUp not flicker, and not to get an occasional "ghost" of a Pop-Up when you don't expect it, after you have hidden it. Not recommended, particularly for newcomers to WinForms, and I never use that code myself anymore, having decided it added no value to my WinForms programming !

Sure, use a Pop-Up, that can be as big as you like, when you mouse over some little icon (like a "help icon") on a Form, or when the user performs some kind of action.

Even consider using other Forms, just to present whatever big chunks of text information you want to give the user. Align them with an edge of the Form you wish them to provide information on: very easy to do.

Show a helper-Form modally, if you really feel the situation involves an issue that warrants "freezing" the use of your application: until the end-user makes a choice.

Or, don't show an information-presenting Form modally: let it persist until the user decides to close it, while the user continues using the your application and its other window(s). If the user moves the main Form, make your helper-Form track it and align again to its edge: easy to achieve !

Or, use a Timer to make helper-Forms, shown non-modally; after they have been made visible: then, fade them out by decreasing their opacity, in the Timer's Tick Event; then close them when they are totally transparent.

In other words: you can make your own Pop-Up equivalents that are not constrained by the boundaries of the Form they are used to provide information about (as long as you don't do something foolish, like making the main Form their Owner).
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

For posterity:

1. Drop a Tooltip control on the form.
2. Add this part in WndProc override:

else if (m.Msg == WM_NCMOUSEMOVE)
  if (m.WParam.ToInt32() == HTCAPTION)
    toolTip1.SetToolTip(this, Text);
base.WndProc(ref m);
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

vjreddy 11-Mar-12 7:33am
Thank you for your response. But creating custom form may pose some other problems. I will go through the articles. But if you find any better solution without creating a custom form, please post solution here. I am voting 5 for the solution, for the effort you have made and interest you have shown. Thank you
aniketyadav7 11-Mar-12 7:37am
yes i am looking for this question. Lets hope for the best.
If in case you find anything related to this then reply me on

Best of luck
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

vjreddy 11-Mar-12 7:18am
I have checked all the links provided by you. But I could not find how to do the following

1. When the text exceeds the title bar width display three dots at the end by truncating the text. By default the windows form Titlebar already truncates the text, but it will not display three dots (ellipses) at the end. The three dots at the end will provide a visual clue to the user that there is some more text.

2. When the user hovers the mouse pointer on title bar how to display a tooltip with full text of the title bar.

Any help will be appreciated. Thank you
aniketyadav7 11-Mar-12 7:21am
Have you seen such application before anywhere? As i haven't seen anything while searching, not even in google. May be i was searching in wrong direction
vjreddy 11-Mar-12 7:27am
I have not seen. But this behaviour I have seen in datagridview. When the text exceeds the width of the column of the datagridview, three dots are displayed at the end, and if you place cursor over the row, the full text is displayed in a tooltip. If the same thing is done for the windows title bar it will be very good.
aniketyadav7 11-Mar-12 7:30am
Like i said, you have to create custom form for such application and for that i have provided you the links. If you are developing new application then go for WPF. because doing this type of thing is a piece of cake in WPF
aniketyadav7 11-Mar-12 7:24am
You have to create your custom form for such application
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

check this out

Public Function SetWidth(ByVal str As String, ByVal fnt As Font, ByVal width As Integer) As String
        Dim rstr As String = Environment.NewLine & str
        Dim pos As Integer = 1
        Dim pos2 As Integer
        While pos < str.Length
            pos = InStr(pos, rstr, " ") + 1
            If pos = 1 Then
                Exit While
            End If
            pos2 = InStrRev(rstr, Environment.NewLine, pos)
            If Me.CreateGraphics.MeasureString(Mid(rstr, pos2, pos - pos2 + 1), fnt).Width > width Then
                rstr = rstr.Insert(InStrRev(rstr, " ", pos - 1), Environment.NewLine)
            End If
        End While
        Return Mid(rstr, 2, rstr.Length - 1)
    End Function

this will wrap ur tooltip and display it properly

Check this out

WinForm Extended[^]
<a href=""></a>[<a href="" target="_blank" title="New Window">^</a>]
<a href=""></a>[<a href="" target="_blank" title="New Window">^</a>]
Shahin Khorshidnia 11-Mar-12 5:42am
aniketyadav7 11-Mar-12 5:45am
Thank you :)
vjreddy 11-Mar-12 5:56am
Please read my question. The requirement is text displayed in the TitleBar of main form of windows application is more than the width of title bar. I don't want to wrap text in the title bar, because this will reduce the height of the application. Instead, when the text exceeds the width of the title bar at the end three dots ... should be displayed. With these three dots at the end users understands that still more text is there and when the user hovers the mouse over the title bar a tooltip showing the full text should be displayed. I searched the MSDN and google but could not find a mouse hover event for the title bar and tooltip for title bar of window. Can you please help.
aniketyadav7 11-Mar-12 6:04am
Looking for that only
vjreddy 11-Mar-12 6:16am
With the solution given above, I can not achieve what is required. Please help
aniketyadav7 11-Mar-12 6:42am
check the links provided. Did not find anything much but i think this will help you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100