Solved

Font styles in CRichEditCtrl

Posted on 1997-08-29
9
608 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

770 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