北京男人是错的,VCL当然没有,我把代码贴出来。 TMouseAwareControl = class(TCustomcontrol) private FEntered: boolean; FmouseEnter: boolean; FBlendvalue: byte; FSelColor: Tcolor; FbtnColor: TColor; procedure CmMouseEnter(var Msg: TMessage); message CM_MOUSEENTER; procedure CmMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE; procedure CMEnter(var Message:TCMEnter); message CM_ENTER; procedure CMExit(var Message:TCMExit); message CM_EXIT; procedure CmFocusedChange(var msg: Tmessage); message CM_FOCUSCHANGED; procedure CmEnabledChange(var msg: TMessage); message CM_ENABLEDCHANGED; procedure SetMouseEnter(const Value: boolean); protected procedure SetEntered(const Value: boolean); virtual; property MouseEnter: boolean read FmouseEnter write SetMouseEnter; property Entered: boolean Read FEntered write SetEntered; public Constructor Create(AOwner: TComponent); override; published property SelColor: Tcolor Read FSelColor Write FselColor; property BlendValue: byte Read FBlendvalue write FBlendValue; property btnColor: TColor read FbtnColor write FbtnColor; property Enabled; property visible; property Font; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property TabOrder; property showhint; end; TDropDownControl = class(TMouseAwareControl) private { Private declarations } FDropDownEnable: boolean; FDropDown: boolean; FDropDownCtrl: TWinControl; FOnCloseUp: TNotifyEvent; FOnDropDown: TNotifyEvent; FFullDropDown: boolean; FShadowPR, FShadowPB: TOfficeXpShadow; FDropDownShadow: boolean; procedure CmCloseUp(var msg: Tmessage); message CM_CLOSEUP; procedure CmFocusedChange(var msg: Tmessage); message CM_FOCUSCHANGED; procedure SetDropdownEnable(const Value: boolean); protected { Protected declarations } procedure SetEntered(const Value: boolean); override; procedure SetDropdowned(const Value: boolean); virtual; procedure Dropdown; dynamic; procedure CloseUp; dynamic; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure paint; override; function getbtnRect: TRect; public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; property DropDowned: boolean read FDropDown write SetDropdowned; [blue]property DropDownCtrl: TWinControl read FDropDownCtrl write FDropDownCtrl;[/blue] published { Published declarations } property DropDownShadow: boolean read FDropDownShadow write FDropDownShadow; property FullDropDown: boolean read FFullDropDown write FFullDropDown; property DropDownEnable: boolean read FDropDownEnable write SetDropdownEnable; property OnCloseUp: TNotifyEvent read FOnCloseUp write FoncloseUp; property OnDropDown: TNotifyEvent read FOnDropDown write FOnDropDown; property parentColor; property color; property align; end; TCommComBox = class(TDropDownControl) private FText: string; FDrawContent: TDrawContent; procedure setText(const Value: string); protected procedure paint; override; public published property Text: string read FText write setText; property onDrawContent: TDrawContent read FDrawContent write FDrawContent; end;关键是下面这个属性,DropDownCtrl 可以是TreeView,可以是panel,可以是listView,DbGrid,是WinControl都可以。property DropDownCtrl: TWinControl read FDropDownCtrl write FDropDownCtrl;下拉实现代码,我这个是有渐变透明阴影(可选),你留意到没有,用到一对鼠标钩子procedure TDropDownControl.Dropdown;var R: TRect;begin// if (ControlCount>0) and (Controls[0] is TWinControl)// then TWinControl(Controls[0]).setFocus// else setFocus; if Assigned(FDropDownCtrl) then with FDropDownCtrl do begin Parent:=getParentForm(self); windows.SetParent(handle, 0); setWindowLong(handle, GWL_STYLE, getWindowLong(handle, GWL_STYLE) or WS_BORDER); setWindowLong(handle, GWL_EXSTYLE, getWindowLong(handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW or WS_EX_TOPMOST);// Parent:=self.Parent; R:=GetPopupRect(self.Parent.ClientToScreen(Point(self.left,self.Top)), BoundsRect, self.Height); Left:=R.Left; Top:=R.Top; if FdropDownShadow then begin FShadowPR.Corner1:=true; FShadowPR.Corner2:=true; FShadowPR.SetBounds(Left+Width, Top, XPMargin, Height); FShadowPR.Prepare; FShadowPB.Corner1:=true; FShadowPB.Corner2:=true; FShadowPB.SetBounds(Left+XPMargin, Top+height, Width, XPMargin); FshadowPB.Prepare; FshadowPR.show(true); FshadowPB.show(true); end; msHookDropDown(self, FDropDownCtrl); visible:=True; end; if Assigned(FOnDropDown) then FOnDropDown(self);end;procedure TDropDownControl.CloseUp;begin if Assigned(FDropDownCtrl) and FDropDownCtrl.HandleAllocated then msHookHide(FDropDownCtrl.handle); FShadowPR.show(false); FShadowPB.show(false); if Assigned(FOnCloseUp) then FOnCloseUp(self);end;