Solved

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

Posted on 2004-04-18
2
585 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
[X]
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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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