Solved

multiple fonts in RichEdit or similar???

Posted on 1998-08-26
3
187 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to send PJL commands to printer 3 89
Using idhttp to login to instagram 2 76
Making delphi communicate with a c# service 16 88
Working with hours 3 46
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now