Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to indent the focus rectangle in an owner-drawn TListBox Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
107
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a TListBox with style lbOwnerDrawVariable. I want to draw some text indented 
10 pixels from the left (this is no problem). However, I also want it so the 
highlighting color and focus rectangle are indented as well (so the 10 pixel margin 
is completely blank, no matter what items are selected). I can't seem to do this 
... the focus rectangle always seems to extend all the way to the left. How do I 
get around this?

Answer:

The problem is that the control as coded draws the focus rectangle after your owner 
drawing code has completed. To override that you have to make a new control 
descending from TListbox (or TCustomlistbox) and give it a handler for the 
CN_DRAWITEM message. Here you need to duplicate what the TCustomlistbox.CNDrawItem 
method does:
1   
2   procedure TMyListBox.CNDrawItem(var message: TWMDrawItem);
3   var
4     State: TOwnerDrawState;
5   begin
6     with message.DrawItemStruct^ do
7     begin
8       State := TOwnerDrawState(LongRec(itemState).Lo);
9       Canvas.Handle := hDC;
10      Canvas.Font := Font;
11      Canvas.Brush := Brush;
12      if (Integer(itemID) >= 0) and (odSelected in State) then
13      begin
14        Canvas.Brush.Color := clHighlight;
15        Canvas.Font.Color := clHighlightText
16      end;
17      if Integer(itemID) >= 0 then
18        DrawItem(itemID, rcItem, State)
19      else
20        Canvas.FillRect(rcItem);
21      if odFocused in State then
22      begin
23        Inc(rcItem.left, 10); {this is the change}
24        DrawFocusRect(hDC, rcItem);
25      end;
26      Canvas.Handle := 0;
27    end;
28  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC