试试ComboBox.Refresh;
看行不行
看行不行
解决方案 »
- SQLSERVER中时间处理函数
- Delphi 应用程序 打包生成 安装软件 的问题————————在线等待!!!!急急急急!!!!!
- Procedure pointer types are always incompatible with method pointer types. Th
- chm文件定位问题
- 我要用Sleep函数,它在哪个包里?
- 求助:是否sql server中主键的问题
- 如何在Windows2000下屏蔽ALT+Tab键
- 窗体的 FormState 出界?急求解决办法 - 100 分
- delphi
- 这个时间型数据相加怎么做?
- 提问‘一个多层应用程序的例子’中我有几处不明白。
- 我在PageControl上放置一个TWebBrowser,想在新开窗口时在后台打开,但是后台打开的页标签的Caption属性要为那个网页的Name!怎么办?
谁有更好的办法?
如果不想删除combobox1.Itemindex:=-1(macro_love(如风)的方法)
unit PicCombo;interfaceuses
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;implementationuses
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.