Click here to Skip to main content
13,551,034 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am a novice in application development.
I have created a app which is expected to display following data in RichEditControl2 in tabular format, but i am facing issue with character spacing.

Date MilsStone Sub
2012-03-12 Requirement/Ticket-Analysis Requirements understanding 2.0
2012-03-14 Design Develop/ Document Design 3.0
2012-03-15 Design Design Review 3.0
2012-03-15 Coding&Unit Testing Develop 4.0

I am unable to set width in this case (using Format() in AddDataToDisplayBox). Please help.

void Csdlc_verifierDlg::AddDataToDisplayBox(int index,COLORREF color, bool bold, bool italic, bool underline)
	CString strTemp;
	char buf[255]={0};
	record_data record = mRecData.GetAt(index);	

int Csdlc_verifierDlg::AddLine(CString str, int seperator, COLORREF color, bool bold, bool italic, bool underline)
	int txtLen = mRichEditCtrl.GetTextLength();

	// Save number of lines before insertion of new text
	int nOldLines = mRichEditCtrl.GetLineCount();

	// Initialize character format structure
	CHARFORMAT cf = {0};
	cf.cbSize = sizeof(CHARFORMAT);
	cf.dwMask = CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_CHARSET|CFM_SPACING; //Mask validates the active field in this case.
	cf.dwEffects = (bold ? CFE_BOLD : 0) | (italic ? CFE_ITALIC : 0) | (underline ? CFE_UNDERLINE : 0);
	cf.crTextColor = color;
	//Add newline character, if required.
	case NEWLINE:

	case SPACE:
		str.AppendChar(' ');
	//Insert data at the end.
	mRichEditCtrl.SetSel(txtLen, -1); // Set the cursor to the end of the text area and deselect everything.
    mRichEditCtrl.ReplaceSel(str); // Inserts when nothing is selected.

    // Apply formating to the just inserted text.
	mRichEditCtrl.SetSel(txtLen-(nOldLines-1), mRichEditCtrl.GetTextLength());
	// Scroll by the number of lines just inserted
	mRichEditCtrl.LineScroll(mRichEditCtrl.GetLineCount() - nOldLines);	
	return 0;
Posted 15-Feb-13 21:13pm
Updated 15-Feb-13 21:18pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

you need to use Tabs.

When formatting the line, insert "\t" in the positions you want tabs, e.g.


Then you need to apply the "paragraph" formatting to the selected area. You need to play with the "tab" positions. Here is example for 2 tabs per line with the format applied for the whole text:

setmem(&pf, 0, sizeof(pf)); // Clear the memory
pf.cbSize = sizeof(pf);
pf.dwMask = PFM_TABSTOPS;
pf.cTabCount = 2; // two tab stops
pf.rgxTabs[0] = 720; // In 10ths of a point
pf.rgxTabs[1] = 1440; // In 10ths of a point
mRichEditCtrl.SetSel(0, -1); // Select all the text
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hi Andrew,
'\t' did not work fine directly in my case, as the text length varied in case of column values. So, it needed an additional logic of calculating the number of tabs.
But thank you for your support.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180515.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100