Solved

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

Posted on 2004-04-18
2
578 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

11 Experts available now in Live!

Get 1:1 Help Now