Solved

Sizin a multiline Edit control so that it's height is equal to the multiline text it contains.

Posted on 2004-08-10
5
372 Views
Last Modified: 2013-11-20
I have multiline edit control with no horizontal scroll, and with vertical scroll. I want to set the height of it so that
no scroll bar is needed, but also should not be more than needed.
I use
SCROLLINFO si;
Height  = CurrentHeight* ((si.nMax + 1)/ si.nPage)

but not satisfied with it.
0
Comment
Question by:hasmet
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 125 total points
ID: 11764295
I think you can make a simulation of painting your text by yourself to establish true height.
Something like

-Create a memory DC
-Create and Select the same font as textbox (This defined in your dialog template). You can use CFont::CreatePointFont()
-Obtain textbox client coordinates
-Use DrawText() using textbox client coordinates and DT_CALCRECT attribute
-Now DrawText() will tell you proper height
-Release DC as usual
-Resize your control as desired.
0
 
LVL 5

Assisted Solution

by:Nass89
Nass89 earned 125 total points
ID: 11780688
Hi,
The following codes do that:
//Define a CEdit variable for your editbox using App Wizard:m_edit1

TEXTMETRIC tm;
CDC* pDC = m_edit1.GetDC();
pDC->GetTextMetrics(&tm);
m_edit1.ReleaseDC(pDC);

CRect r;
int Height=m_edit1.GetLineCount()*tm.tmHeight;
WINDOWPLACEMENT wp;
m_edit1.GetWindowPlacement(&wp);
r.left=wp.rcNormalPosition.left;
r.top=wp.rcNormalPosition.top;
r.right=wp.rcNormalPosition.right;
r.bottom=wp.rcNormalPosition.top+Height;

m_edit1.MoveWindow(r);
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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

943 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

1 Experts available now in Live!

Get 1:1 Help Now