Solved

How do I show Tool tip for Multiline Edit box?

Posted on 2008-10-15
7
1,533 Views
Last Modified: 2013-11-25
I have Multiline edit box. i need to show tool tip for the edit box. How can i set the tool tip text?
0
Comment
Question by:LearningCpp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:tchamtieh
ID: 22719444
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22723407
Here is one possible solution:

1. Add a CToolTipCtrl http://msdn.microsoft.com/en-us/library/6b4cb3a5(VS.80).aspx member variable to you CDialog derived class:

CToolTipCtrl m_myToolTip;

2. Add the PreTranslateMessage method to your class:

afx_msg BOOL PreTranslateMessage(MSG * pMsg); // in the .h file

BOOL CMFCAppDlg::PreTranslateMessage(MSG * pMsg) // in the .cpp file
{
      m_myToolTip.RelayEvent(pMsg);

      return CDialog::PreTranslateMessage(pMsg);
}

3. Map you multi-line text box to a control variable and call it e.g. m_myMultiLineTextBox

4. Add the following code to the OnInit method of your class:

	if(m_myToolTip.Create(this)) {
		m_myToolTip.AddTool( &m_myMultiLineTextBox, _T("You are hovering over the text box!"));
		m_myToolTip.Activate(TRUE);
	}
	else {
		AfxMessageBox(_T("Unable to create the tool tip."));
	}

Open in new window

Output.png
0
 

Author Comment

by:LearningCpp
ID: 22730514
If multiline Edit box contains different strings on different line, then i want to display the contents of each line in tooltip.
Suppose Multiline edit box has:
Test1
Test2
Test3
Then i need to show all these data in tool tio and not the fixed string as you have shown.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:LearningCpp
ID: 22730855
I forgot to tell you that i have various controls on my UI. and i need to show tooltip for all the controls.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22732095
You can add the tooltip for each control, see the following line in the OnInitDialog method:

m_myToolTip.AddTool(&m_myControlVariable, _T("Tooltip for the control"));
You can call this method several times passing to it your control mapped variable and its tooltip text.
As far as a tooltip for individual lines within a CEdit control is concerned I am not aware of a technique to do so as individual lines are not objects and furthermore change if the CEdit control is resized so it seems it would be necessary to write an algorithm to calculate the position of the mouse within the CEdit control, determine the line and based upon that show a tooltip; this would be rather complex. Perhaps you could switch to a list control and implement the tooltips for its individual items.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22732921
Sorry, I might have misunderstood your question about dynamically setting the tooltip text, you can basically set the text value of the tooltip anytime like for example during an event such as on change then retrieve the value of your text box and set the tool tip to its text:

CString sToolTip;
m_TextBox.GetWindowTextW(sToolTip);
m_myToolTip.AddTool(&m_TextBox, sToolTip);
0
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 250 total points
ID: 22732955
...and regarding the multiline ability for that you will have to extend and customize the tool tip class, here is one article regarding this enhancement:

http://www.codeproject.com/KB/miscctrl/tooltipex.aspx
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question