Help Center

CRichEditCtx.SetSelectionCharFormatmethod

Windowsmethoddocumented

Syntax

FUNCTION SetSelectionCharFormat (BYREF cf AS CHARFORMATW) AS BOOLEAN
Also documented as CharFormat — one description covers them all.

Parameters

NameDescription
fOption(GET) Specifies the range of text from which to retrieve formatting. It can be one of the following values.
SCF_DEFAULT The default character formatting.
SCF_SELECTION The current selection's character formatting.
chfmt(SET) Character formatting that applies to the control. If this parameter is zero, the default character format is set. Otherwise, it can be one of the following values (see Formatting values below).
cf(SET) A CHARFORMATW structure specifying the character formatting to use. Only the formatting attributes specified by the dwMask member are changed. The szFaceName and bCharSet members may be overruled when invalid for characters, for example: Arial on kanji characters.

Return value

(GET) Returns a CHARFORMATW structure with the attributes of the first character. The dwMask member specifies which attributes are consistent throughout the entire selection. For example, if the entire selection is either in italics or not in italics, CFM_ITALIC is set; if the selection is partly in italics and partly not, CFM_ITALIC is not set.

(SET) If the operation succeeds, the return value is a nonzero value. If the operation fails, the return value is zero. Call GetErrorInfo to get information about the result.

Description

Gets/sets the current character formatting in a rich edit control.

Gets/sets the default character formatting in a rich edit control.

Gets/sets the character formatting attributes of the current selection.

Gets/sets the character formatting attributes for the currently selected word.

Examples

(GET) PROPERTY CharFormat (BYVAL fOption AS DWORD) AS CHARFORMATW (SET) PROPERTY CharFormat (BYVAL chfmt AS DWORD, BYREF cf AS CHARFORMATW)

(GET) PROPERTY DefaultCharFormat () AS CHARFORMATW (SET) PROPERTY DefaultCharFormat (BYREF cf AS CHARFORMATW)

(GET) PROPERTY SelectionCharFormat () AS CHARFORMATW (SET) PROPERTY SelectionCharFormat (BYREF cf AS CHARFORMATW)

(GET) PROPERTY WordCharFormat () AS CHARFORMATW (SET) PROPERTY WordCharFormat (BYREF cf AS CHARFORMATW)

pRichEdit.ExSetSel(98, 113) ' // Select word at position 98, 113 DIM cf AS CHARFORMAT cf.dwMask = CFM_COLOR ' // Let's set the color cf.crTextColor = BGR(255, 0, 0) ' // Red color pRichEdit.SelectionCharFormat = cf ' // Set the color pRichEdit.HideSelection(TRUE) ' // Hide selection

pRichEdit.ExSetSel(98, 113) ' // Select word at position 98, 113 DIM cf AS CHARFORMAT cf.dwMask = CFM_BOLD ' // The CFE_BOLD value of the dwEffects member is valid. cf.dwEffects = CFE_BOLD ' // Characters are bold pRichEdit.SelectionCharFormat = cf ' // Set the format pRichEdit.HideSelection(TRUE) ' // Hide selection

pRichEdit.ExSetSel(98, 113) ' // Select word at position 98, 113 DIM cf AS CHARFORMAT cf.dwMask = CFM_SIZE ' // The yHeight member is valid. cf.yHeight = 12 * 20 ' // Character height, in twips (1/1440 of an inch or 1/20 of a printer's point) pRichEdit.SelectionCharFormat = cf ' // Set the format pRichEdit.HideSelection(TRUE) ' // Hide selection

Select text and change color Select text and make it bold Select text and change the font height

Reference

  • Defined in AfxNova/CRichEditCtx.inc:952
  • Documented in Windows/WIndows Controls/RichEdit/CRichEditCtx Class.md
  • Topic: CRichEditCtx Class