2013-02-16 68 views
0

我是应用程序开发的新手。 我已经创建了一个应用程序,它应该以表格格式在RichEditControl2中显示以下数据,但是我正面临着字符间距的问题。如何以丰富的编辑控件打印表格格式的数据

日期MilsStone子 2012-03-12要求/票务分析需求的理解2.0 2012-03-14设计开发/文档设计3.0 2012-03-15设计设计评审3.0 2012-03-15编码& Unit Testing Develop 4.0

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

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

回答

0

要在丰富的编辑控件创建列对齐,你需要创建一个固定的空间字体,如“快递”,并设置字体为使用mRichEditCtrl.SetFont(...)的控制;

可以通过使用列之间的制表符'\ t'来创建一些具有比例空间字体的列对齐效果,但只有当每行文本的列的文本宽度大致相同时才有效。如果一行使用完整的50个字符,而另一行只有几个字符,则单个'\ t'不足以进行对齐。对于这些情况,您需要进行额外的处理,根据列中的字符数计算要插入的选项卡数量。

+0

感谢了很多马克。 “Courier”字体解决方案确实达到了目的。 – Varun 2013-02-18 11:48:58

0

,如果你是来自同一所学校,或刚刚张贴在不同的论坛同样的问题,一看便知here

+0

喜茶,我已经张贴在不同的论坛上相同的查询,事实上,它一直为我好。 – Varun 2013-02-18 11:55:13