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(Send er: TObject);
//Purpose : To Prepare the form with a New Blank Document
Begin
fontlistfill(self);
listFont.ItemIndex := 0;
listFontClick(self);
End;
procedure TfrmWriter.fontlistfill(Se nder: 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.listFontDrawIte m(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.ItemIn dex];
Font.Size := 0;
TextOut(Rect.Left+1, Rect.Top+1, listFont.Items[Index]);
End;
end;
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(Send
//Purpose : To Prepare the form with a New Blank Document
Begin
fontlistfill(self);
listFont.ItemIndex := 0;
listFontClick(self);
End;
procedure TfrmWriter.fontlistfill(Se
// Purpose: Create all the font items in the list box
var
fontCounter : integer;
begin
fontCounter := 0;
while fontCounter < 8 Do
begin
listFont.Items[fontCounter
fontCounter := fontCounter + 1;
end;
end;
procedure TfrmWriter.listFontDrawIte
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.ItemIn
Font.Size := 0;
TextOut(Rect.Left+1, Rect.Top+1, listFont.Items[Index]);
End;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It seams that you need use Invalidate after programmatically changes maded to list.