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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 45
sum28 challenge 31 115
mapAB Challlenge 35 159
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 874
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…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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