Solved

Font styles in CRichEditCtrl

Posted on 1997-08-29
9
613 Views
Last Modified: 2013-12-03
I need to display a few text strings in CRichEditCtrl in format:
<property name>: <property value>
Example:
      Name: Tom Ross
      SSN: 111-11-1111
My problem is that I have to display propery as "bold" and value as "italic". CRichEditCtrl class supply methods to change font style only for selected text, but I can not afford do it this way since user will
flashes when text would selected/deselected.


0
Comment
Question by:gelbert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:davmarc
ID: 1305230
Did you try this way (pseudo-code):
 SetSelectionCharFormat(BOLD)
 Write property name
 SetSelectionCharFormat(ITALIC)
 Write property value
 Loop till no more properties
Since you change the style just before writing, you don't need to select any text, so it shouldn't flash.

Davide Marcato.
0
 
LVL 8

Author Comment

by:gelbert
ID: 1305231
Thanks for answer but I need additional information.
To show text in the Rich Edit control I from CStringArrays which I have I do following:
 
int iCount = pNames->GetSize() - 1;

 // make sure that array is not empty
 if ( -1 != iCount )
 {
       CString sText = "";
       for( int i = 0; i < iCount; i++ )
       {
      sText += ( pNames->GetAt(i) + ": " + pValues->GetAt(i) + "\n" );
       }

     // do not add next line symbol to last line
    sText += ( pNames->GetAt(iCount) + ": " + pValues->GetAt(iCount) );

    SetWindowText( sText );
}

So where od you suggest I should make SetSelectionCharFormat() call?
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1305232
You cannot apply my solution to this code.
You must find a good way for your needs to write each piece of the text char-by-char, not with SetWindowText().

Did you try your solution but adding SetRedraw(FALSE) in the beginning and SetRedraw(TRUE) before returning?
This might prevent the redraw of the richedit control after each selection.

Davide Marcato.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:gelbert
ID: 1305233
I have some general guesses in which direction should I look, so I keep trying ( like now I trying to display text in OnDraw() using TextOut() to display text and SelectObject() to change font, for now it does not work).
     What I am looking is working advice how to get where I want to be ... ( Have text displayed in RichEditCtrl with some words in pne font and other words in another or different style ).  Thanks for your attempt to help me, but I need more then guess.
0
 
LVL 8

Author Comment

by:gelbert
ID: 1305234
Adjusted points to 150
0
 
LVL 4

Accepted Solution

by:
davmarc earned 150 total points
ID: 1305235
Another idea that has just come up...put your text in RTF format into the clipboard, and tell the richedit control to paste the content of the clipboard?

Davide Marcato.
0
 
LVL 8

Author Comment

by:gelbert
ID: 1305236
thanks Davide, it sounds like a good idea. Any sample code?
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1305237
I've found a cleaner solution: use CRichEditCtrl::StreamIn() to insert your RTF-compliant text in the control.
Tell me your E-Mail address if you want he full RTF official specification.

Davide Marcato.
0
 
LVL 8

Author Comment

by:gelbert
ID: 1305238
My email address is gelbert@interport.com. Thanks for your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question