Click here to Skip to main content
15,905,682 members
Home / Discussions / C#
   

C#

 
GeneralRe: Theoretical Question on object creation Pin
Blake Coverett22-Sep-03 23:32
Blake Coverett22-Sep-03 23:32 
GeneralRe: Theoretical Question on object creation Pin
Blake Coverett22-Sep-03 23:30
Blake Coverett22-Sep-03 23:30 
QuestionHow do i convert an image to cursor? Pin
Gywox22-Sep-03 23:05
Gywox22-Sep-03 23:05 
GeneralChange User Windows Rights Pin
marsiglia22-Sep-03 22:54
marsiglia22-Sep-03 22:54 
GeneralRe: Change User Windows Rights Pin
shaunAustin22-Sep-03 23:22
shaunAustin22-Sep-03 23:22 
GeneralQuick boolean question: DataGrids.DataSource: multi datatables Pin
troels_sorensen22-Sep-03 22:44
troels_sorensen22-Sep-03 22:44 
Generalencode a path to binary and store to database Pin
M_|222-Sep-03 22:03
M_|222-Sep-03 22:03 
GeneralRe: encode a path to binary and store to database Pin
shaunAustin22-Sep-03 23:28
shaunAustin22-Sep-03 23:28 
GeneralDLL CAll Pin
anees8122-Sep-03 20:56
anees8122-Sep-03 20:56 
Questionhow to use c# to sned message to a mobile phone Pin
Jim Chan22-Sep-03 20:20
Jim Chan22-Sep-03 20:20 
GeneralIntegral Number of Lines in RichTextBox Pin
Andrew Shapira22-Sep-03 18:08
Andrew Shapira22-Sep-03 18:08 
GeneralRe: Integral Number of Lines in RichTextBox Pin
Blake Coverett22-Sep-03 22:14
Blake Coverett22-Sep-03 22:14 
GeneralRe: Integral Number of Lines in RichTextBox Pin
Andrew Shapira22-Sep-03 22:26
Andrew Shapira22-Sep-03 22:26 
GeneralRe: Integral Number of Lines in RichTextBox Pin
Blake Coverett22-Sep-03 23:09
Blake Coverett22-Sep-03 23:09 
GeneralRe: Integral Number of Lines in RichTextBox Pin
Blake Coverett22-Sep-03 23:20
Blake Coverett22-Sep-03 23:20 
And here's a chunk of code that does exactly what you are looking for with a pair of RichEdit controls separated by a splitter. Digging out the bit that applies to just the top RichEdit is left as an exercise to the reader. Warning - old Win32 code, no MFC, no WTL, no CLR, just C++/Win32. The math however is still the same.

void CConsole::ReSize(int *pcx, int *pcy, BOOL bSnap)
{
	int cx = GetSystemMetrics(SM_CXEDGE);
	int cy = GetSystemMetrics(SM_CYEDGE);
	int nScrollWidth = GetSystemMetrics(SM_CXVSCROLL) + 
		GetSystemMetrics(SM_CXBORDER);
	int nSepHeight = GetSystemMetrics(SM_CYFIXEDFRAME);

	RECT r;
	SendMessage(m_hOutput, EM_GETRECT, 0, LPARAM(&r));
	cx += r.left;
	cy += r.top;

	if (pcx && pcx) {
		if (bSnap) {
			RECT r;
			r.top = r.left = 0;
			r.right = m_nCols * m_nCharWidth + 2 * cx + nScrollWidth;
			r.bottom = (m_nOutputRows + m_nInputRows) * m_nCharHeight + 4 * cy 
				+ nSepHeight + m_nStatusHeight;
			AdjustWindowRectEx(&r, GetWindowLong(m_hWnd, GWL_STYLE), 
				BOOL(GetMenu(m_hWnd)), GetWindowLong(m_hWnd, GWL_EXSTYLE));
			*pcx = r.right - r.left;
			*pcy = r.bottom - r.top;
		} else {
			int cxClient = *pcx, cyClient = *pcy;
			RECT r;
			r.left = 0; r.top = 0;
			r.right = *pcx; r.bottom = *pcy;
			AdjustWindowRectEx(&r, GetWindowLong(m_hWnd, GWL_STYLE), 
				BOOL(GetMenu(m_hWnd)), GetWindowLong(m_hWnd, GWL_EXSTYLE));
			int cxOld = cxClient -= r.right - r.left - *pcx;
			int cyOld = cyClient -= r.bottom - r.top - *pcy;

			m_nCols = max(0, (cxClient - 2 * cx - nScrollWidth
				+ m_nCharWidth / 2) / m_nCharWidth);
			cxClient = m_nCols * m_nCharWidth + 2 * cx + nScrollWidth;

			int nTotalRows = max(0, (cyClient - 4 * cy - nSepHeight 
				- m_nStatusHeight + m_nCharHeight / 2) / m_nCharHeight);
			cyClient = nTotalRows * m_nCharHeight + 4 * cy 
				+ nSepHeight + m_nStatusHeight;

			m_nOutputRows = nTotalRows - m_nInputRows;
			if (m_nOutputRows < 0) {
				m_nInputRows += m_nOutputRows;
				m_nOutputRows = 0;
			}

			*pcx += cxClient - cxOld;
			*pcy += cyClient - cyOld;
		}
	}

	HDWP hdwp = BeginDeferWindowPos(3);
	hdwp = DeferWindowPos(hdwp, m_hOutput, NULL, 0, 0, 
		m_nCols * m_nCharWidth + 2 * cx + nScrollWidth, 
		m_nOutputRows * m_nCharHeight + 2 * cy, 
		SWP_NOACTIVATE | SWP_NOZORDER);
	hdwp = DeferWindowPos(hdwp, m_hInput, NULL, 0, 
		m_nOutputRows * m_nCharHeight + 2 * cy + nSepHeight, 
		m_nCols * m_nCharWidth + 2 * cx + nScrollWidth,
		m_nInputRows * m_nCharHeight + 2 * cy, 
		SWP_NOACTIVATE | SWP_NOZORDER);
	hdwp = DeferWindowPos(hdwp, m_hStatus, NULL, 0,
		(m_nInputRows + m_nOutputRows) * m_nCharHeight + 4 * cy + nSepHeight,
		m_nCols * m_nCharWidth + 2 * cx + nScrollWidth, m_nStatusHeight, 
		SWP_NOACTIVATE | SWP_NOZORDER);
	EndDeferWindowPos(hdwp);
}


--
-Blake (com/bcdev/blake)
GeneralRe: Integral Number of Lines in RichTextBox Pin
Andrew Shapira23-Sep-03 0:06
Andrew Shapira23-Sep-03 0:06 
GeneralRe: Integral Number of Lines in RichTextBox Pin
Blake Coverett23-Sep-03 5:58
Blake Coverett23-Sep-03 5:58 
GeneralRe: Integral Number of Lines in RichTextBox Pin
Andrew Shapira23-Sep-03 9:12
Andrew Shapira23-Sep-03 9:12 
GeneralRe: Integral Number of Lines in RichTextBox Pin
Andrew Shapira23-Sep-03 0:01
Andrew Shapira23-Sep-03 0:01 
Generalnewbie trying to Pinvoke Pin
jpervaz22-Sep-03 17:33
jpervaz22-Sep-03 17:33 
GeneralRe: newbie trying to Pinvoke Pin
Blake Coverett22-Sep-03 17:51
Blake Coverett22-Sep-03 17:51 
GeneralRe: newbie trying to Pinvoke Pin
jpervaz23-Sep-03 3:40
jpervaz23-Sep-03 3:40 
GeneralRe: newbie trying to Pinvoke Pin
Blake Coverett23-Sep-03 6:10
Blake Coverett23-Sep-03 6:10 
Generalbuilding a canned email sender Pin
frank2122-Sep-03 14:05
frank2122-Sep-03 14:05 
GeneralRe: building a canned email sender Pin
fadee22-Sep-03 20:43
fadee22-Sep-03 20:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.