Solved

multiple fonts in RichEdit or similar???

Posted on 1998-08-26
3
189 Views
Last Modified: 2013-12-02
I need an edit box that can handle multiple fonts on one line. Basically I need to have characters from the symbols font mixed in with standard fonts (Times New Roman). Can the Rich Edit box handle this? If so, can you give me an example of how to do this.

Thanks
0
Comment
Question by:Kmiller
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 200 total points
ID: 1337854
Hi,
Yes, you can use any font in the richedit control, and...
.here's a simple example:

  procedure TForm1.ChangeFontBtnClick(Sender: TObject);
  var
    s: TTextAttributes; // just shorter names...
    f: TFont;
  begin
    if ( FontDialog1.Execute ) then
    begin  
      s := RichEdit1.SelAttributes;
      f := FontDialog1.Font;  
      s.Name  := f.Name;
      s.Color := f.Color;
      s.Size  := f.Size;
      s.Style := f.Style;
    end;
    RichEdit1.SetFocus; // return to edit control
  end;

/// John
0
 

Author Comment

by:Kmiller
ID: 1337855
I know how to set one font within the RichEdit box. What I'm looking for is an example of how to use more then one font in one line. So an example of how to alternate between the fonts MS Sans Serif and Symbol for each charecter in a line is what I'm looking for.

Thanks
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337856
Hi,
The way i showed you is how to do it. However, here's a more concrete example of entering a func:

procedure TForm1.FormulaBtnClick(Sender: TObject);
const
  n1 = 'Times New Roman';
  n2 = 'Symbol';
begin
  with RichEdit1 do begin
    with SelAttributes do begin
      Name := n1; SelText := 'B = ( ';
      Name := n2; SelText := 'm';
      Name := n1; SelText := '0 ';
      Name := n2; SelText := '´ m';
      Name := n1; SelText := 'r ';
      Name := n2; SelText := '´ ';
      Name := n1; SelText := 'I ';
      Name := n2; SelText := '´ ';
      Name := n1; SelText := 'N ) / ( 2 ';
      Name := n2; SelText := '´ p ';
      Name := n1; SelText := ') ';
      Name := n2; SelText := '´ ';
      Name := n1; SelText := '( 2 / ( ro + ri ) )';
    end;
  end;
end;

Or, something more elaborate, like this:

procedure InsertRichFormula( RichEdit: TRichEdit; sFormula, sFontName1, sFontName2: string );
var
  iIndex, iLast, iCode: Integer;
  bCode        : Boolean;
  sTemp        : string;
begin
  iLast := 0;
  bCode := False;
  sTemp := '';
  with RichEdit do
  with SelAttributes do begin
    for iIndex := 1 to Length( sFormula ) do begin
      if ( sFormula[ iIndex ] = '\' )
      then bCode := True
      else begin
        if ( bCode ) then begin
          bCode := False; // reset
          iCode := StrToInt( sFormula[ iIndex ] );
          if ( iLast <> iCode ) then begin
            SelText := sTemp; sTemp := '';
            iLast := iCode;
            case iCode of 1 : Name := sFontName1; 2 : Name := sFontName2; end;
          end;
        end else AppendStr( sTemp, sFormula[ iIndex ] );
      end;
    end;
    SelText := sTemp;
  end;
end;

procedure TForm1.FormulaBtnClick(Sender: TObject);
const
  n1 = 'Times New Roman';
  n2 = 'Symbol';
begin
  InsertRichFormula(
    RichEdit1,
    '\1B = ( \2m\10 \2´ m\1r \2´ \1I \2´ \1N ) / ( 2 \2´ p \1) \2´ \1( 2 / ( ro + ri ) )',
    n1, n2
  );
end;

/// John
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

792 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