如何在丰富的编辑控件中以表格格式打印数据 [英] how to print data in tabular format in rich edit control

查看:109
本文介绍了如何在丰富的编辑控件中以表格格式打印数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是应用程序开发的新手。

我创建了一个应用程序,它希望以表格格式在RichEditControl2中显示以下数据,但我面临着字符间距问题。



日期MilsStone Sub

2012-03-12要求/票证 - 分析要求理解2.0

2012-03-14设计开发/文档设计3.0

2012-03-15设计设计评论3.0

2012-03-15编码和单元测试开发4.0



在这种情况下我无法设置宽度(使用AddDataToDisplayBox中的Format())。请帮忙。



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);	
	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>

推荐答案

您需要使用标签。



格式化行时,在想要标签的位置插入\t,例如



you need to use Tabs.

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

strTemp.Format("%-15s\t%-50s%-50s%-5s\t%-15s",record.date,record.milestone,record.tasktype,record.effort,record.name);





然后您需要将段落格式应用于所选区域。你需要玩标签位置。下面是每行2个标签的示例,其格式适用于整个文本:





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:

PARAFORMAT pf;
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
mRichEditCtrl.SetParaFormat(pf);


安德鲁,

''\ t''在我的情况下没有直接正常工作,因为文本长度因列值而异。因此,它需要一个计算标签数量的额外逻辑。

但是,谢谢你的支持。
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.


这篇关于如何在丰富的编辑控件中以表格格式打印数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆