Board index » delphi » subscript, superscript in a TRichEdit

subscript, superscript in a TRichEdit

Hi
Anybody know how to set subscript, superscript in a TRichEdit control during run time (like any other editor).
Thnx
Ukumashi

 

Re:subscript, superscript in a TRichEdit


See a code below (sorry but don't remember where I found it):
**********************************************
type
  TCharacterFormat = (CFM_Superscript, CFM_Subscript, CFM_Normal);

procedure RE_SetCharFormat(RichEdit: TRichEdit; CharacterFormat:
TCharacterFormat);
var
  // The CHARFORMAT structure contains information about
  // character formatting in a rich edit control.
  Format: TCharFormat;
begin
  FillChar(Format, SizeOf(Format), 0);
  with Format do
  begin
    cbSize := SizeOf(Format);
    dwMask := CFM_OFFSET;
    // Character offset, in twips, from the baseline.
    // If the value of this member is positive,
    // the character is a superscript;
    // if it is negative, the character is a subscript.
    case CharacterFormat of
      CFM_Superscript: yOffset := 60;
      CFM_Subscript: yOffset := -60;
      CFM_Normal: yOffset := 0;
    end;
  end;
  // The EM_SETCHARFORMAT message sets character formatting in a rich edit
control.
  // SCF_SELECTION: Applies the formatting to the current selection
  Richedit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
end;

// Examples:

// Apply Subscript to the current selection
procedure TForm1.Button1Click(Sender: TObject);
begin
  RE_SetCharFormat(RichEdit1, CFM_Superscript);
end;

// Apply ubscript to the current selection
procedure TForm1.Button2Click(Sender: TObject);
begin
  RE_SetCharFormat(RichEdit1, CFM_Subscript);
end;
**********************************************

--
With best regards, Mike Shkolnik
EMail: mshkol...@scalabium.com
http://www.scalabium.com

"Ukmashi" <nambiar_...@hotmail.com> ???Y/???Y ????? ???Y??:
news:3e09863e$1@newsgroups.borland.com...

Quote

> Hi
> Anybody know how to set subscript, superscript in a TRichEdit control

during run time (like any other editor).
Quote
> Thnx
> Ukumashi

Other Threads