MFC CRichEdit改變指定地區的背景色和字型 .

來源:互聯網
上載者:User
注:m_richedit代表ID為IDC_RICHEDIT1的CRichEditCtrl控制項的control類型的變數

1. 如何使用richedit添加AfxInitRichEdit();
CxxxApp::InitInstance()
{
AfxInitRichEdit();
.............
}

       AfxInitRichEdit()功能:裝載 RichEdit 1.0 Control (RICHED32.DLL).

2. 改變richedit指定地區的文字顏色及字型

        CHARFORMAT cf;
ZeroMemory(&cf, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |
CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
cf.dwEffects = 0;
cf.yHeight = 12*12;//文字高度
cf.crTextColor = RGB(200, 100, 255); //文字顏色
strcpy(cf.szFaceName ,_T("隸書"));//設定字型
m_richedit.SetSel(1, 5); //設定處理地區
m_richedit.SetSelectionCharFormat(cf);

3.  改變richedit指定地區的文字背景顏色

        CHARFORMAT2 cf; //聲明為CHARFORMAT2結構,詳細見MSDN
ZeroMemory(&cf, sizeof(CHARFORMAT2));
cf.cbSize = sizeof(CHARFORMAT2);
cf.dwMask = CFM_BACKCOLOR;         cf.crBackColor=RGB(0, 255, 0); //背景顏色為綠色
m_richedit.SetSel(0, 2); //設定處理地區               

m_richedit.SendMessage(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf);

 4.只修改指定地區文字的背景顏色

先指定選擇地區

m_richedit1.SetSel(0, 19); //設定處理地區

m_richedit1.HideSelection(FALSE, TRUE);//顯示選擇的地區背景 很重要

Changes the visibility of the selection.

 
void HideSelection(   BOOL bHide,   BOOL bPerm );
Parameters
bHide

Indicates if the selection should be shown or hidden, TRUE to hide the selection.

bPerm

Indicates if this change in visibility for the selection should be permanent.

Remarks

When bPerm is TRUE, it changes the
ECO_NOHIDESEL option for this CRichEditCtrl object. For a brief description of this option, see SetOptions. You can use this function to set all the options for this
CRichEditCtrl object.

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.