Solved

How do I show Tool tip for Multiline Edit box?

Posted on 2008-10-15
7
1,529 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
lucky13 challenge 11 120
has77  challenge 9 72
Execute multiple curl cmds with sleep and send output to file 10 88
Problem to open text file 11 69
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now