Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
4.25/5 (4 votes)
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
Comments
patar sii miaw 11-Mar-12 4:34am    
you can set the tooltip on from the game.
VJ Reddy 11-Mar-12 5:57am    
I could not under stand what you want to say. Can you please elaborate.

check this out

C#
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[^]

http://www.scribd.com/doc/80374027/9/Set-the-Title-Bar-Text-in-a-Windows-Form-Object

XML
http://msdn.microsoft.com/en-us/library/windows/desktop/aa974176.aspx

<a href="http://nemerle.org/wiki/index.php?title=System.Windows.Forms_tutorial">http://nemerle.org/wiki/index.php?title=System.Windows.Forms_tutorial</a>[<a href="http://nemerle.org/wiki/index.php?title=System.Windows.Forms_tutorial" target="_blank" title="New Window">^</a>]

<a href="http://allapi.mentalis.org/apilist/GetWindowTextLength.shtml">http://allapi.mentalis.org/apilist/GetWindowTextLength.shtml</a>[<a href="http://allapi.mentalis.org/apilist/GetWindowTextLength.shtml" target="_blank" title="New Window">^</a>]
 
Share this answer
 
v3
Comments
Shahin Khorshidnia 11-Mar-12 5:42am    
+5
Aniket Yadav 11-Mar-12 5:45am    
Thank you :)
VJ Reddy 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.
Aniket Yadav 11-Mar-12 6:04am    
Looking for that only
VJ Reddy 11-Mar-12 6:16am    
With the solution given above, I can not achieve what is required. Please help
 
Share this answer
 
Comments
VJ Reddy 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
Aniket Yadav 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 aniketyadav7@gmail.com

Best of luck
 
Share this answer
 
Comments
VJ Reddy 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
Aniket Yadav 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
VJ Reddy 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.
Aniket Yadav 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
Aniket Yadav 11-Mar-12 7:24am    
You have to create your custom form for such application
<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).
 
Share this answer
 
v2
For posterity:

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

C#
else if (m.Msg == WM_NCMOUSEMOVE)
{
  if (m.WParam.ToInt32() == HTCAPTION)
  {
    toolTip1.SetToolTip(this, Text);
  }
}
base.WndProc(ref m);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900