?
Solved

How do I show Tool tip for Multiline Edit box?

Posted on 2008-10-15
7
Medium Priority
?
1,536 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

771 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