-.自己修改组件,可以吗?如果可以,请给出示例代码
2.其他方法
2.其他方法
解决方案 »
- FTP客户端上传的失败开发过程
- 获取image控件中位图数据区的地址
- 在DBGRID里提取全部数据
- >>>>>重庆美女网上相亲,回答上问题的程序员立即成亲<<<<<<
- 在D6下调用EXCEL出现的问题。
- 求一个dephi打开ms visual foxpro 表的例程
- 有谁知道联众四国军旗游戏储存棋子布局(即:图像组件属性文件)文件的加密方法吗?
- 在多层结构中如何使用BatchMove?
- 关于dbchart的问题?请教
- 请问有没有什么Delphi函数参考手册的好书,介绍一下!
- 求助!!!! Time.OnTimer := CheckConnection; //此处出现问题!!!why
- delphi中如何杀死进程?
Windows, SysUtils, Classes, Controls, ExtCtrls, Graphics, Messages, StdCtrls;type
TMyListBox = class(TListBox)
private
procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
protected
procedure DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState); override;
public
constructor Create(AOwner: TComponent); override;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('WGYKING', [TMyListBox]);
end;{ TMyListBox }procedure TMyListBox.CNDrawItem(var Message: TWMDrawItem);
var
State: TOwnerDrawState;
begin
with Message.DrawItemStruct^ do
begin
State := TOwnerDrawState(LongRec(itemState).Lo);
Canvas.Handle := hDC;
Canvas.Font := Font;
Canvas.Brush := Brush;
if (Integer(itemID) >= 0) and (odSelected in State) then
begin
Canvas.Brush.Color := clHighlight;
Canvas.Font.Color := clHighlightText
end;
if Integer(itemID) >= 0 then
DrawItem(itemID, rcItem, State) else
Canvas.FillRect(rcItem);
//if odFocused in State then DrawFocusRect(hDC, rcItem);
Canvas.Handle := 0;
end;
end;constructor TMyListBox.Create(AOwner: TComponent);
begin
inherited;
Style := lbOwnerDrawFixed;
end;procedure TMyListBox.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
var
Flags: Longint;
Data: String;
begin
inherited;
if Assigned(OnDrawItem) then OnDrawItem(Self, Index, Rect, State) else
begin
Canvas.FillRect(Rect);
if Index < Count then
begin
Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
if not UseRightToLeftAlignment then
Inc(Rect.Left, 2)
else
Dec(Rect.Right, 2);
Data := '';
if (Style in [lbVirtual, lbVirtualOwnerDraw]) then
Data := DoGetData(Index)
else
Data := Items[Index];
DrawText(Canvas.Handle, PChar(Data), Length(Data), Rect, Flags);
end;
end;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, Grids, ExtCtrls, Unit2;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
ListBox: TMyListBox;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox := TMyListBox.Create(Self);
ListBox.Parent := Self;
ListBox.Items.Add('AAAAAAAAAAA');
ListBox.Items.Add('BBBBBBBBBBB');
ListBox.Items.Add('CCCCCCCCCCC');
ListBox.Items.Add('DDDDDDDDDDD');
end;end.
Style不能为lbStandard型
可以为其他类型没有其他限制了^_^