Delphi能不能做出半透明的Edit和Memo控件 不能,不过可以做两个memo该它的visible,让他们轮流显示。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ′ó???ìé?μ?£??£í?????óD°??ú£oò???ê???í??÷μ?Memo???tμ?′ú??£ounit TrMemo;{$R-}interfaceuses Windows, Messages, Controls, StdCtrls, Classes;const TMWM__SpecialInvalidate = WM_USER + 1111;type TTransparentMemo = class(TMemo) private procedure SpecialInvalidate(var Message:TMessage); message TMWM__SpecialInvalidate; procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL; procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL; procedure WMSetText(var Message:TWMSetText); message WM_SETTEXT; procedure CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT); message CN_CTLCOLOREDIT; procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN; procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; protected procedure CreateParams(var Params: TCreateParams); override; public constructor Create(AOwner: TComponent); override; end;procedure Register;implementation{ TTransparentMemo }procedure TTransparentMemo.WMHScroll(var Message: TWMHScroll);begin inherited; PostMessage(Handle,TMWM__SpecialInvalidate,0,0);end;procedure TTransparentMemo.WMVScroll(var Message: TWMVScroll);begin SendMessage(Handle,TMWM__SpecialInvalidate,0,0); inherited; PostMessage(Handle,TMWM__SpecialInvalidate,0,0);end;procedure TTransparentMemo.CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT);begin with Message do begin SetBkMode(ChildDC,TRANSPARENT); Result:=GetStockObject(HOLLOW_BRUSH) endend;procedure TTransparentMemo.WMSetText(var Message:TWMSetText);begin inherited; if not (csDesigning in ComponentState) then PostMessage(Handle,TMWM__SpecialInvalidate,0,0)end;procedure TTransparentMemo.SpecialInvalidate(var Message:TMessage);var r:TRect;begin if Parent<>nil then begin r:=ClientRect; r.TopLeft:=Parent.ScreenToClient(ClientToScreen(r.TopLeft)); r.BottomRight:=Parent.ScreenToClient(ClientToScreen(r.BottomRight)); InvalidateRect(Parent.Handle,@r,true); RedrawWindow(Handle,nil,0,RDW_FRAME+RDW_INVALIDATE) end;end;procedure TTransparentMemo.WMKeyDown(var Message: TWMKeyDown);begin SendMessage(Handle,TMWM__SpecialInvalidate,0,0); inherited; PostMessage(Handle,TMWM__SpecialInvalidate,0,0);end;procedure TTransparentMemo.WMEraseBkgnd(var Message: TWMEraseBkgnd);begin Message.Result := 1;end;constructor TTransparentMemo.Create(AOwner: TComponent);begin inherited; ControlStyle := [csCaptureMouse, csDesignInteractive, csClickEvents, csSetCaption, csOpaque, csDoubleClicks, csReplicatable, csNoStdEvents];end;procedure TTransparentMemo.CreateParams(var Params: TCreateParams);begin inherited CreateParams(Params); with Params do begin ExStyle:=ExStyle or WS_EX_TRANSPARENT and not WS_EX_WINDOWEDGE and not WS_EX_STATICEDGE and not WS_EX_DLGMODALFRAME and not WS_EX_CLIENTEDGE; end;end;procedure Register;begin RegisterComponents('cool!', [tTransparentMemo]);end;end. ) ? ????
unit TrMemo;{$R-}
interfaceuses
Windows, Messages, Controls, StdCtrls, Classes;const
TMWM__SpecialInvalidate = WM_USER + 1111;type
TTransparentMemo = class(TMemo)
private
procedure SpecialInvalidate(var Message:TMessage); message TMWM__SpecialInvalidate;
procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;
procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
procedure WMSetText(var Message:TWMSetText); message WM_SETTEXT;
procedure CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT); message CN_CTLCOLOREDIT;
procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
end;procedure Register;implementation{ TTransparentMemo }
procedure TTransparentMemo.WMHScroll(var Message: TWMHScroll);
begin
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;procedure TTransparentMemo.WMVScroll(var Message: TWMVScroll);
begin
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;procedure TTransparentMemo.CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT);
begin
with Message do
begin
SetBkMode(ChildDC,TRANSPARENT);
Result:=GetStockObject(HOLLOW_BRUSH)
end
end;procedure TTransparentMemo.WMSetText(var Message:TWMSetText);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0)
end;procedure TTransparentMemo.SpecialInvalidate(var Message:TMessage);
var r:TRect;
begin
if Parent<>nil then
begin
r:=ClientRect;
r.TopLeft:=Parent.ScreenToClient(ClientToScreen(r.TopLeft));
r.BottomRight:=Parent.ScreenToClient(ClientToScreen(r.BottomRight));
InvalidateRect(Parent.Handle,@r,true);
RedrawWindow(Handle,nil,0,RDW_FRAME+RDW_INVALIDATE)
end;
end;procedure TTransparentMemo.WMKeyDown(var Message: TWMKeyDown);
begin
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;procedure TTransparentMemo.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
Message.Result := 1;
end;constructor TTransparentMemo.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := [csCaptureMouse, csDesignInteractive, csClickEvents,
csSetCaption, csOpaque, csDoubleClicks, csReplicatable, csNoStdEvents];
end;procedure TTransparentMemo.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
ExStyle:=ExStyle or WS_EX_TRANSPARENT and not WS_EX_WINDOWEDGE
and not WS_EX_STATICEDGE and not WS_EX_DLGMODALFRAME and not WS_EX_CLIENTEDGE;
end;
end;procedure Register;
begin
RegisterComponents('cool!', [tTransparentMemo]);
end;end. ) ? ????