Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
413 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 500 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 500 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

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

886 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