Link to home
Start Free TrialLog in
Avatar of myleseven1
myleseven1

asked on

Getting a listbox to display specific font names in their actual font style.

Hi there

Im trying to make a Word Processor program. I want a list box to display specific Font types and each Font type to be drawen in its actual font style. I've been having problems with the updating the list box automatically when it is created. Using the DrawItem event to change each font style works but only after you click on the actual item in the list box. The fonts are stored in an array.

Solution to this problem would be greatly appreciated.

Cheers
myleseven1

Below is my code so far...

procedure TfrmWriter.FormCreate(Sender: TObject);
//Purpose : To Prepare the form with a New Blank Document
Begin
  fontlistfill(self);
  listFont.ItemIndex := 0;
  listFontClick(self);
End;

procedure TfrmWriter.fontlistfill(Sender: TObject);
// Purpose: Create all the font items in the list box
var
  fontCounter : integer;
begin
  fontCounter := 0;
  while fontCounter < 8 Do
    begin
      listFont.Items[fontCounter] := fontsArray[fontCounter];
      fontCounter := fontCounter + 1;
    end;
end;

procedure TfrmWriter.listFontDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
// Purpose: Update all the font names to their actual font style
begin
  inherited;
  With listFont.Canvas Do
  Begin
      FillRect(Rect);
      Font.Name := fontsArray[listFont.ItemIndex];
      Font.Size := 0;
      TextOut(Rect.Left+1, Rect.Top+1, listFont.Items[Index]);
  End;
end;

ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikProg
MikProg

It seams that you need use Invalidate after programmatically changes maded to list.