Solved

multiple fonts in RichEdit or similar???

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 141
Send message from delphi to whatsapp, is it possible? 3 1,432
Run video youtube webbrowse 10 61
Delphi and Access based Enumeration 9 63
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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