Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-04-18
2
582 Views
Last Modified: 2013-12-03
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;

0
Comment
Question by:myleseven1
2 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 250 total points
ID: 10855426
Try changin your ListFontDrawItem method like this:

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[Index];
      Font.Size := 0;
      TextOut(Rect.Left+1, Rect.Top+1, listFont.Items[Index]);
  End;
end;

Cheers,

Raymond.

0
 
LVL 3

Expert Comment

by:MikProg
ID: 10856765
It seams that you need use Invalidate after programmatically changes maded to list.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 317
Identify font 3 98
Performance of SQL statement 37 127
Unique identifier on a terminal server (rdp) 4 67
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…

828 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