Board index » delphi » Fonts in TPW TEdit.

Fonts in TPW TEdit.

I am currently writing an application for private use. Basically,
I want to be able to read a file and display it for editting and then
print it off or save it. I will deal with the printing later but
at the moment I just want to be able to edit it. I have used the
distribution stdwnds.pas and stdwnds.res to make use of the
TFileWindow object defined there and everything works as it is
supposed to. The problem is that I want to change the font of the
text so that it is of fixed width (modern) rather than variable
width. Is there a simple way to do this? I have traced back through the
object heirarchy and cannot find a method or attr or field to change. I
have tried overriding the paint method but that is ignored. The only way
I can think of tackling it is to define the TEdit object in a resource
and change the FONT there. However, doesn't the new object effectively
occupy a new window seperate from the parent window containing the edit
menu? I am surprised that the manual does not contain the relevant
information if such a change is possible and would be equally surprised
if it were not.
I assume that the same solution would be applied to TStatic objects.

Thanks to anyone who replies,

Fiona Stephen

 

Re:Fonts in TPW TEdit.


Quote
eta...@festival.ed.ac.uk (Fiona Stephen) writes:
>I am currently writing an application for private use. Basically,
>I want to be able to read a file and display it for editting and then
>print it off or save it. I will deal with the printing later but
>at the moment I just want to be able to edit it. I have used the
>distribution stdwnds.pas and stdwnds.res to make use of the
>TFileWindow object defined there and everything works as it is
>supposed to. The problem is that I want to change the font of the
>text so that it is of fixed width (modern) rather than variable
>width. Is there a simple way to do this? [snip]

I have now solved my problem with much appreciated help from Dominique
Lovy. I added the method below to the TEditWindow object in StdWnds.pas.
This was then called in TFileWindow.SetUpWindow by MakeFont(editor^.Hwindow).
Thus the method makes the Font and wm_SetFont message is sent to
Editor^.Hwindow to change the Font.

Thanks to anyone who thought about it and Dominique Lovy for her help.

Fiona Stephen.

procedure TEditWindow.MakeFont(Recipient:HWnd);
Var
   reply:integer;
   Message:Tmessage;
begin
  FillChar(ALogFont, SizeOf(TLogFont), #0);
  with ALogFont do
  begin
    lfHeight        := 18;     {Make a large font                 }
    lfWeight        := 600;    {Indicate a Bold attribute         }
    lfItalic        := 0;      {Non-zero value indicates italic   }
    lfUnderline     := 0;      {Non-zero value indicates underline}
    lfOutPrecision  := Out_Default_Precis;
    lfClipPrecision := Clip_Default_Precis;
    lfQuality       := Proof_Quality;
    lfPitchAndFamily:= Fixed_Pitch;
    StrCopy(lfFaceName, 'Courier');
  end;
  DeleteObject(TheFont);
  TheFont:=CreateFontIndirect(ALogFont);
  SendMessage(Recipient,wm_SetFont,TheFont,1);
end;

Other Threads