Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 57
Firemonkey android show image from resource ? 1 42
Tidtcpserver listening on multiports? 1 27
enhance the following code 3 31
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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