This paper uses ListBox self-painting to achieve two special effects (see Figure), the left style is what you thinkually trigger, the right style comes from "C Builder Research", the old demon is implemented, here Delphi implements it.
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 the author original, please contact me before reprinting, please indicate the source of 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 is committed to BCB learning discussion and research' # 13'ccrun '); lsbright.items.add (' Programming Handshase 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 Handbook'); 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 background color and fill 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.Left 3, Rect.top 3, Rect.right - 2, Rect.Bottom - 2, 8, 8); // Different widths and highly draw once, implement three-dimensional effects 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