CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Location
    Singapore
    Posts
    34

    Changing Fonts in RichEdit Control

    Hi,

    I want to change the default font of the Rich Edit control at run time.

    I tried making use of CRichEditCtrl::SetDefaultCharFormat() function
    and changing the szFaceName member of CHARFORMAT structure. It did not work.
    The function help says "Only the attributes specified by the dwMask member of cf are
    changed by this function." I did not see any attribute that can be used to change the
    font.
    I tried this before putting any text in the control.

    Can anyone one tell me how to change font of Rich Edit control at run time?

    Cheers,
    Sanjeet


  2. #2
    Join Date
    Jun 1999
    Posts
    27

    Re: Changing Fonts in RichEdit Control

    Hi,

    Maybe try the "SetFont()" function (CWnd method). This should change the font for the entire text (I don't know if it's what you want).

    Greetz
    Jean-Marie


  3. #3
    Join Date
    Jun 1999
    Posts
    23

    Re: Changing Fonts in RichEdit Control

    To Sanjeet

    Try this.

    int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CRichEditView::OnCreate(lpCreateStruct) == -1)
    return -1;

    CHARFORMAT cfDefault;
    cfDefault.cbSize = sizeof(cfDefault);
    cfDefault.dwEffects = CFE_PROTECTED;
    cfDefault.dwMask = CFM_BOLD | CFM_FACE | CFM_SIZE | CFM_CHARSET | CFM_PROTECTED | CFM_COLOR;
    cfDefault.yHeight = 12 * 20;
    cfDefault.crTextColor = RGB(255,255,0);
    cfDefault.bCharSet = 0;
    strcpy( cfDefault.szFaceName, _T("Courier New") );// or "Times New Roman" etc etc

    GetRichEditCtrl().SetDefaultCharFormat(cfDefault);
    GetRichEditCtrl().SetEventMask(ENM_CHANGE | ENM_SELCHANGE | ENM_PROTECTED);
    GetRichEditCtrl().SetBackgroundColor( FALSE, RGB(0,0,0) );

    return 0;
    }



  4. #4
    Join Date
    Apr 1999
    Location
    Singapore
    Posts
    34

    Re: Changing Fonts in RichEdit Control

    Thanks Matthew,

    I did not use the code sent by you. But got where I was going wrong.
    Actually it was a stupid mistake on my side.
    I never noticed the dwMask value "CFM_FACE". After reading I set this value and
    it worked.

    Thanks again.
    Sanjeet.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured