Solved

multiple fonts in RichEdit or similar???

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

19 Experts available now in Live!

Get 1:1 Help Now