Solved

How do I show Tool tip for Multiline Edit box?

Posted on 2008-10-15
7
1,528 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
Comment Utility
0
 
LVL 19

Expert Comment

by:LordOfPorts
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:LearningCpp
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
...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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
only14 challenge 19 63
EvenOdd challenge 10 81
Change to event 1 72
Microsoft C++ code failing in executable that worked 9 50
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…

763 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

12 Experts available now in Live!

Get 1:1 Help Now