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
365 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

15 Experts available now in Live!

Get 1:1 Help Now