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
406 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
[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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

615 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