Click here to Skip to main content
15,894,720 members

how to print data in tabular format in rich edit control

VM2012 asked:

Open original thread
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.

C++
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);	
	strTemp.Format("%-15s%-50s%-50s%-5s%-15s",record.date,record.milestone,record.tasktype,record.effort,record.name);	
	AddLine(strTemp,NEWLINE,color,bold,italic,underline);
}

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.
	switch(seperator)
	{
	case NEWLINE:
		str.AppendChar('\n');
		break;

	case SPACE:
		str.AppendChar(' ');
		break;
	}
	//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());
    mRichEditCtrl.SetSelectionCharFormat(cf);
	
	// Scroll by the number of lines just inserted
	mRichEditCtrl.LineScroll(mRichEditCtrl.GetLineCount() - nOldLines);	
	return 0;
}
<code></code>
Tags: C++, MFC

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900