求一类似Tcombobox的图象控件(有源代码的给双倍的分)(100分)

  • 主题发起人 主题发起人 iqinxyz
  • 开始时间 开始时间
I

iqinxyz

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,
小生在此求一类似TCombobox的图象控件,能象它一样控制图象!
大家用过QQ吗?就是那个能显示头象的控件!谢谢!(有源代码的给双倍的分)
 
用ExpressBars中间有一个控件dxSpinImage可以实现你的要求,发给你?
 
标准的ComboBox 100%就可以实现
 
to startcn:
发给我好吗? 我的Email:alinq@263.net!
 
to startcn:
请发给我好吗?我给你分!<a href="mailto:alinq@263.net">alinq@263.net</a>
 
www.inprises.com
 
to balaschen:
可以给我源程序吗?Email:<a href="mailto:alinq@263.net">alinq@263.net</a>
 
原来做过,明天给你原码!
 
To iqinxyz:
自己做做吧,设置ComboBox的Style属性为csOwnerDrawFixed用一个TImageList存放你要
的图片,然后在ComboBox的OnDrawItem用
ImageList1.Draw(ComboBox1.Canvas,Rect.Left,Rect.Top,Index);就可以了,当然要做的
好看还需要根据State画出选中当前焦点等,你也很容易把她包装成一个控件来用。
 
写了一个控件
unit PicCombo;

interface

uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
StdCtrls, ImgList;

type
TPicCombo = class(TCustomComboBox)
private
FImages: TCustomImageList;
FImageChangeLink: TChangeLink;
procedure SetImages(const Value: TCustomImageList);

procedure ImageListChange(Sender: TObject);
protected
procedure DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState); override;
procedure MeasureItem(Index: Integer; var Height: Integer); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;

procedure CalcSize;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Images: TCustomImageList read FImages write SetImages;

property Anchors;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property DropDownCount;
property Enabled;
property ImeMode;
property ImeName;
property ParentColor;
property ParentCtl3D;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDropDown;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnStartDock;
property OnStartDrag;
end;

procedure Register;

implementation

uses
CommCtrl;

procedure Register;
begin
RegisterComponents('Samples', [TPicCombo]);
end;

{ TPicCombo }

procedure TPicCombo.CalcSize;
var
i: Integer;
begin
if Assigned(FImages) then begin
Height := FImages.Height + 4;
ItemHeight := FImages.Height;
Width := GetSystemMetrics(SM_CXHSCROLL) + 4 + FImages.Width;
Items.Clear;
for i := 0 to FImages.Count - 1 do
Items.Add('');
end;
end;

constructor TPicCombo.Create(AOwner: TComponent);
begin
inherited;
Style := csOwnerDrawFixed;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := ImageListChange;
end;

destructor TPicCombo.Destroy;
begin
FImageChangeLink.Free;
inherited;
end;

procedure TPicCombo.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
begin
if not Assigned(FImages) then Exit;
if [odSelected, odFocused] * State <> [] then
Canvas.Brush.Color := clHighlight
else Canvas.Brush.Color := Color;
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(Rect);
ImageList_Draw(FImages.Handle, Index, Canvas.Handle,
Rect.Left, Rect.Top, ILD_NORMAL or ILD_TRANSPARENT);
end;

procedure TPicCombo.ImageListChange(Sender: TObject);
begin
if HandleAllocated and (Sender = Images) then CalcSize;
end;

procedure TPicCombo.MeasureItem(Index: Integer; var Height: Integer);
begin
//do nothing
end;

procedure TPicCombo.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (AComponent = FImages) and (Operation = opRemove) then
Images := nil;
end;

procedure TPicCombo.SetImages(const Value: TCustomImageList);
begin
if Assigned(FImages) then
FImages.UnRegisterChanges(FImageChangeLink);
FImages := Value;
if Assigned(FImages) then begin
FImages.RegisterChanges(FImageChangeLink);
FImages.FreeNotification(Self);
end;
CalcSize;
end;

end.
 
你的源代码我研究了一番,也用了,非常好,受益匪浅。
有一点,combobox的高度,受限制,不能象oicq那么大,应该怎么解决?
跟imegelist有关系吗?请指教
 
解决了,就是imagelist的事,怪我没试就瞎说,delete * from up
 
我还没有看,你自己就搞定了,呵呵.
 
[:D]在此感谢[red]balaschen[/red]和[red]JohnsonGuo[/red],
给balaschen加[red]40[/red]分,JohnsonGuo加[red]60[/red]分!
 
多人接受答案了。
 

Similar threads

回复
0
查看
1K
不得闲
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部