Transferred from
http://blog.9cbs.net/nhconch/archive/2004/12/05/205127.aspx
This paper uses ListBox self-painting to achieve two special effects, two of the two styles from C Builder research www.ccrun.com, the old demon is implemented, and now convert it into a Delphi code.
Demo Picture: // --------------------------------------------- ----------------------------- Unit DrawlistItem; Interface Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ImgList, jpeg, ExtCtrls; type TForm1 = class (TForm) lsbRight: TListBox; ImageList1: TImageList; staticText1: TStaticText; lsbLeft: TListBox; imgHouse: TImage; imgHouseGray: TImage; procedure FormCreate (Sender: TObject); procedure lsbRightDrawItem (Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure lsbRightClick (Sender: TObject); procedure FormShow (Sender: TObject); procedure lsbLeftDrawItem (Control: TWinControl; Index: Integer; Rect: TRect; State: TownerDrawState; private public {public declarations} End; var form1: tform1; importation {$ r * .dfm} {======================== ========================================================== Design By: Peng Guoi Date: 2004-11-29 Site: http:// Kacarto n.yeah.net/ blog: http://blog.9cbs.net/nhconch email: kacarton@sohu.com Articles are original, please contact me before reprinting, please indicate the article, retain the author information, Thank you for your support! ============================================================================================================================================================================================================= =========
===============} procedure tform1.form; var i: integer; begin lsbright.style: = lbownerdrawfixed; lsbright.ctl3d: = false; lsbright.ItemHeight: = 50; lsbright.items.add ('C Builder Research www.ccrun.com' # 13 'is committed to BCB learning discussion and research' # 13'ccrun (old demon) '); lsbright.items.add (' programming Handbook My Developer Knowledge Base '# 13'http://blog.9cbs.net/nhconch'#13' Scorpio Butterfly '); for i: = 3 to 10 Do Begin Lsbright.Items.Add (' Listbox Items Of ' INTOSTR (I) # 13'second of ' INTOSTR (i) # 13'third of' INTOSTR (I)); end; lsbleft.style: = lbownerdrawfixed; lsbleft.ctl3d: = false; lsbleft.itemheight: = 90; lsbleft.items.add ('Programming Hands "; lsbleft.items.add (' My Developer Knowledge Base '); lsbleft.items.add (' Webmaster: Scorpio '); lsbleft.Items.add ( 'http://blog.9cbs.net/nhconch');end; procedure TForm1.lsbRightDrawItem (Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var strTemp: String; begin // text color lsbRight .Canvas.font.color: = CLBLACK ; // Set the background color and fill the background lsbright.canvas.brush.color: = CLWHITE; lsbright.canvas.FillRect (Rect); // Set the rounded rectangular color and draw rounded rectangular lsbright.canvas.brush.color: = TCOLOR ($ 00fff7f7); lsbright.canvas.pen.color: = Tcolor ($ 00131315); lsbright.canvas.RoundRect (Rect.Light 3, Rect.top 3, Rect.right - 2, Rect.Bottom - 2 , 8, 8); // Draw once with different widths and heights, implement three-dimensional effect Lsbright.canvas.RoundRect (Rect.Left 3, Rect.top 3, Rect.right - 3, Rect.Bottom - 3 , 5, 5);
// If it is the current IF (Odselected in State), the rounded rectangular Lsbright.canvas.brush.color: = TCanvas.roundRect (Rect.Top 3, Rect.top 3, Rect.right - 3, Rect.Bottom - 3, 5); // Select the text color lsbright.canvas.font.color: = CLBLUE; // If the current item has a focus, draw the focus dadder box, turn the XOR operation when the system is plotted to achieve the destination IF (odfocused in state) of the wipping focus, and ilcused in state)., RECT); END; / / Picture IMAGELIST1.DRAW (Lsbright.canvas, Rect.LEFT 7, Rect.Top (Lsbright.ItemHeight - Imaglist1.Height) Div 2, Index, True); // Draw three lines of text Strtemp: = Lsbright.items.strings [index]; lsbright.canvas.textout (Rect.Top 4, Copy (strTemp, 1, POS (# 13, strTemp) -1); startemp: = COPY (Strtemp, POS (# 13, strTemp) 1, Length (strTemp)); lsbright.canvas.textout (Rect.LEFT 32 10, Rect.top 18, Copy (strTemp, 1, POS (# 13 , strTemp) -1)); lsbright .Canvas.textout (Rect.Top 32 10, Rect.top 32, Copy (strTemp, POS (# 13, strTemp) 1, Length (strTemp))); end; procedure tform1.lsbrightclick (sender: Tobject ); begin StaticText1.Caption: = '' lsbRight.Items.Strings [lsbRight.ItemIndex]; end; procedure TForm1.FormShow (Sender: TObject); begin lsbRight.ItemIndex: = 0; lsbRight.Repaint (); lsbLeft. ItemIndex: = 0; lsbleft.repaint (); end; procedure tform1.lsbleftddddddrawitem (Control: TwinControl; index: integer; reference; state: towerdrawstate); var r: TRECT