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 create non-selectable separator lines in a TComboBox 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
86
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to create non-selectable separator lines in a TComboBox

Answer:

Note that the Combobox1.Style is csOwnerDrawvariable.

1   procedure TForm1.FormCreate(Sender: TObject);
2   begin
3     with combobox1 do
4     begin
5       items.add('Item 1');
6       items.add('Item 2');
7       items.addObject('Item 3', Pointer(1));
8       Perform(CB_SetItemHeight, 2, ItemHeight + 5);
9       items.add('Item 4');
10      items.add('Item 5');
11    end;
12  end;
13  
14  procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index: Integer;
15    var Height: Integer);
16  begin
17    Height := (Control as TCombobox).Itemheight;
18  end;
19  
20  procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
21    Rect: TRect; State: TOwnerDrawState);
22  var
23    needsSeparator: Boolean;
24  begin
25    with Control as TCombobox do
26    begin
27      needsSeparator := Assigned(Items.Objects[index]) and not (odComboBoxEdit in 
28  State);
29      if needsSeparator then
30        Rect.Bottom := Rect.Bottom - 5;
31      Canvas.FillRect(Rect);
32      Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top, Items[index]);
33      if needsSeparator then
34      begin
35        Rect.Top := Rect.Bottom;
36        Rect.Bottom := Rect.Bottom + 5;
37        Canvas.Brush.Color := color;
38        Canvas.Pen.Color := font.Color;
39        Canvas.Pen.Style := psSolid;
40        Canvas.Fillrect(Rect);
41        Canvas.MoveTo(rect.left, rect.top + 2);
42        Canvas.LineTo(rect.right, rect.top + 2);
43      end;
44    end;
45  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