Solved

multiple fonts in RichEdit or similar???

Posted on 1998-08-26
3
191 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
[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
  • 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

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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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