📄 qyuyulistbox.pas
字号:
unit QYuyuListBox;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Dialogs, windows, Graphics;
type
TYuyuListBox = class(TListBox)
private
fFontColor :TColor;
fBackGroundColor :TColor;
fAOWner :TComponent;
fImageList :TImageList;
procedure OnYuyuDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
protected
{ Protected declarations }
public
Constructor Create(AOwner :TComponent);override;
published
property FontColor :TColor read fFontColor write fFontColor;
property BackGroundColor :TColor read fBackGroundColor write fBackGroundColor;
property ImageList :TImageList read fImageList write fImageList;
end;
implementation
{ TYuyuListBox }
constructor TYuyuListBox.Create(AOwner: TComponent);
begin
inherited Create(AOWner);
self.Style :=lbOwnerDrawFixed;
self.Ctl3D :=false;
self.ItemHeight :=50;
fFontColor :=clBlue;
fBackGroundColor := tcolor($00FF8080);
fAOWner :=AOWner;
Self.OnDrawItem :=Self.OnYuyuDrawItem;
end;
Procedure TYuyuListBox.OnYuyuDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
str :string; //同t
p :integer; //查找变量
t :Boolean; //淋时变量
i :Integer;
begin
self.Canvas.Brush.Color :=clwhite;
self.Canvas.FillRect(rect);
self.Canvas.Brush.Color :=clwhite;
self.Canvas.Pen.Color :=clblack;
self.Canvas.RoundRect(rect.Left +5,rect.Top +5,rect.Right -4,rect.Bottom -4,10,10);
self.Canvas.RoundRect(rect.Left +5,rect.Top +5,rect.Right -5,rect.Bottom -5,10,10);
if odselected in state then
begin
self.Canvas.Font.Color :=fFontColor ;
self.Canvas.FillRect(rect);
self.Canvas.Brush.Color :=fBackGroundColor;
self.Canvas.Pen.Color :=clblack;
self.Canvas.RoundRect(rect.Left +5,rect.Top +5,rect.Right -4,rect.Bottom -4,10,10);
self.Canvas.RoundRect(rect.Left +5,rect.Top +5,rect.Right -5,rect.Bottom -5,10,10);
if odfocused in state then
drawfocusrect(self.Canvas.Handle ,rect);
end;
if fImageList<>nil then
begin
fimagelist.Draw(Canvas,10,rect.Top +(ItemHeight -fimagelist.Height ) div 2,index);
t :=true;
end
else
t :=false;
str :=self.Items.Strings [index];
p :=1;
i :=0;
while p<>0 do
begin
p :=pos(#13,str);
if p>0 then
begin
if t then
self.Canvas.TextOut(rect.Left +40,rect.Top +i*self.Font.size +self.Font.size,copy(str,1,p-1))
else
self.Canvas.TextOut(rect.Left +15,rect.Top +i*self.Font.size +self.Font.size ,copy(str,1,p-1));
str :=copy(str,p+2,length(str)-p+2);
end
else
if t then
self.Canvas.TextOut(rect.Left +40,rect.Top +i*self.Font.Height +self.Font.size,str)
else
self.Canvas.TextOut(rect.Left +15,rect.Top +i*self.Font.Height+ self.Font.size,str)
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -