求edit,memo,ComboBox等输入控件透明话并去边框,怎么弄???(50分)

  • 主题发起人 主题发起人 yuting2003
  • 开始时间 开始时间
Y

yuting2003

Unregistered / Unconfirmed
GUEST, unregistred user!
求edit,memo,ComboBox等输入控件透明话并去边框,怎么弄??
谢谢大家,
 
edit和memo好弄,把它们的BorderStyle设为bsNone;
ComboBox太麻烦,可以用下面的方法试试
var
hdcself: Windows.HDC;
hpenself: Windows.HPEN;
Rt: TRect;
begin
inherited;
hdcself := Windows.GetDC(Handle);
hpenself := Windows.CreatePen(PS_SOLID, 1, CurrentColor);

Windows.SelectObject(hdcself, hpenself);
//Windows.Rectangle(hdcLB, 0, 0, self.Width, self.Height);
Windows.GetClientRect(Handle, Rt);
Windows.DeleteDC(hdcself);
建议自己重写一个组件吧.
因为即使去掉外边框,下拉的箭头还是影响效果.
 
我需要的是控件透明,edit是放在Image上面的,我要的效果是控件透明,能看到下面的Image图片
 
我才写的,不过 上下滚动的时候,文字会重叠
这个是 richedit
unit QTMRichEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, ComCtrls,Windows,Messages;
const
TMWM__SpecialInvalidate = WM_USER + 2222;
type
TTMRichEdit = class(TRichEdit)
private
{ Private declarations }
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 CNCTLCOLORMSGBOX(var Message:TWMCTLCOLORMSGBOX);
message CN_CTLCOLORMSGBOX;
procedure CNCTLCOLORSTATIC(var Message:TWMCTLCOLORSTATIC);
message CN_CTLCOLORSTATIC;
procedure WMKeyDown(var Message: TWMKeyDown);
message WM_KEYDOWN;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd);
message WM_ERASEBKGND;
procedure WMMove(var Message: TMessage);
message WM_MOVE;
procedure CMMouseEnter(var Message: TMessage);
message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage);
message CM_MOUSELEAVE;
//procedure WMMouseMove (Var Message: TWMMouseMove);
Message WM_MouseMove;
procedure WMLButtonDown(Var Message: TWMLButtonDown);
Message WM_LButtonDown;
procedure WMKillFocus(Var Message: TWMKillFocus);
Message WM_KillFocus;
procedure WMMOUSEWHEELl(var Message:TMessage);message WM_MOUSEWHEEL;

protected
{ Protected declarations }
procedure CreateParams(var Params: TCreateParams);
override;
procedure CreateWnd;override;
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
published
{ Published declarations }
end;

procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TTMRichEdit]);
end;

{ TTMRichEdit }
procedure TTMRichEdit.CMMouseEnter(var Message: TMessage);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMRichEdit.CMMouseLeave(var Message: TMessage);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMRichEdit.CNCTLCOLOREDIT(var Message: TWMCTLCOLOREDIT);
begin
with Messagedo
begin
SetBkMode(ChildDC,Windows.TRANSPARENT);
Result:=GetStockObject(HOLLOW_BRUSH)
//Result:=NullBrush;
end
end;

procedure TTMRichEdit.CNCTLCOLORMSGBOX(var Message: TWMCTLCOLORMSGBOX);
begin
Message.Result:=-1;
end;

procedure TTMRichEdit.CNCTLCOLORSTATIC(var Message: TWMCTLCOLORSTATIC);
begin
Message.Result:=-1;
end;

constructor TTMRichEdit.Create(AOwner: TComponent);
begin
inherited create(AOwner);;
//ControlStyle := [csCaptureMouse, csDesignInteractive, csClickEvents,
// csSetCaption, csOpaque, csDoubleClicks, csReplicatable, csNoStdEvents];
//FTransParent:=True;
end;

procedure TTMRichEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Paramsdo
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 TTMRichEdit.CreateWnd;
begin
inherited CreateWnd;
SetWindowLong(Parent.Handle, GWL_STYLE,
GetWindowLong(Parent.Handle, GWL_STYLE) and not WS_CLIPCHILDREN);
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle,GWL_EXSTYLE) or WS_EX_TRANSPARENT);
end;

procedure TTMRichEdit.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;
Message.Result:=1;
end;

procedure TTMRichEdit.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
Update;
Message.Result := 1;
end;

procedure TTMRichEdit.WMHScroll(var Message: TWMHScroll);
begin
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMRichEdit.WMKeyDown(var Message: TWMKeyDown);
begin
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMRichEdit.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0)
end;

procedure TTMRichEdit.WMLButtonDown(var Message: TWMLButtonDown);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMRichEdit.WMMOUSEWHEELl(var Message: TMessage);
begin
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
if Message.Result = 0 then
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
Update;
end;

procedure TTMRichEdit.WMMove(var Message: TMessage);
begin
inherited;
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMRichEdit.WMSetText(var Message: TWMSetText);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0)
end;

procedure TTMRichEdit.WMVScroll(var Message: TWMVScroll);
begin
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

end.
 
edit 的
unit QClarityEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;

const
TMWM__SpecialInvalidate = WM_USER + 1111;
type
TClarityEdit = class(TEdit)
private
FClarity : Boolean;
procedure SetClarity(const Value: Boolean);
{ Private declarations }
protected
{ Protected declarations }
procedure CMEraseBkgnd (var Message: TWMEraseBkgnd);
Message WM_ERASEBKGND;
procedure WMSetText (var Message: TWMSetText);
procedure SpecialInvalidate(var Message: TMessage);
message TMWM__SpecialInvalidate;
procedure CNCTLCOLOREDIT (var Message: TWMCTLCOLOREDIT);
message CN_CTLCOLOREDIT;
procedure WMKeyDown (var Message: TWMKeyDown);
message WM_KEYDOWN;
procedure WMKillFocus (Var Message: TWMKillFocus);
Message WM_KillFocus;
procedure WMLButtonDown (Var Message: TWMLButtonDown);
Message WM_LButtonDown;
procedure WMMove (Var Message: TWMLButtonDown);
Message WM_Move;
procedure WMMouseMove (Var Message: TWMMouseMove);
Message WM_MouseMove;
procedure CreateParams(var Params: TCreateParams);
override;
procedure CreateWnd;
override;
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
procedure Invalidate;
override;
property Clarity:Boolean read FClarity write SetClarity default True;
published
{ Published declarations }
property BevelKind default BKFlat;
property BorderStyle default bsNone;
end;

procedure Register;
implementation
procedure Register;
begin
RegisterComponents('subin', [TClarityEdit]);
end;

{ TClarityEdit }
procedure TClarityEdit.CMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
if Clarity then
Message.Result := 1;
end;

procedure TClarityEdit.CNCTLCOLOREDIT(var Message: TWMCTLCOLOREDIT);
begin
if Clarity then
with Messagedo
begin
SetBkMode(ChildDC,Windows.TRANSPARENT);
Result:=GetStockObject(HOLLOW_BRUSH);
end
else
inherited;
end;

constructor TClarityEdit.Create(AOwner: TComponent);
begin
inherited create(AOwner);
self.BorderStyle:=bsNone;
self.BevelKind:=bkflat;
Clarity:=true;
end;

procedure TClarityEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
if (CsDesigning in ComponentState) then
exit;
with Paramsdo
begin
ExStyle:=ExStyle or WS_EX_TRANSPARENT;
end;
end;

procedure TClarityEdit.CreateWnd;
begin
inherited CreateWnd;
if Clarity then
begin
SetWindowLong(Parent.Handle, GWL_STYLE,
GetWindowLong(Parent.Handle, GWL_STYLE) and not WS_CLIPCHILDREN);
end;
end;

procedure TClarityEdit.Invalidate;
begin
if Clarity then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0)
else
inherited;
end;

procedure TClarityEdit.SetClarity(const Value: Boolean);
begin
FClarity := Value;
end;

procedure TClarityEdit.SpecialInvalidate(var Message: TMessage);
var
rect:TRect;
begin
if Parent<>nil then
begin
rect:=ClientRect;
rect.TopLeft:=Parent.ScreenToClient(ClientToScreen(rect.TopLeft));
rect.BottomRight:=Parent.ScreenToClient(ClientToScreen(rect.BottomRight));
InvalidateRect(Parent.Handle,@rect,true);
RedrawWindow(Handle,nil,0,RDW_FRAME+RDW_INVALIDATE)
end;
end;

procedure TClarityEdit.WMKeyDown(var Message: TWMKeyDown);
begin
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TClarityEdit.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0)
end;

procedure TClarityEdit.WMLButtonDown(var Message: TWMLButtonDown);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TClarityEdit.WMMouseMove(var Message: TWMMouseMove);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TClarityEdit.WMMove(var Message: TWMLButtonDown);
begin
inherited;
//if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TClarityEdit.WMSetText(var Message: TWMSetText);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

end.
 
memo 的
unit QTMMemo;
interface
uses
Windows, Messages, Controls, StdCtrls, Classes;
const
TMWM__SpecialInvalidate = WM_USER + 1111;

type
TTMMemo = class(TMemo)
private
{ Private declarations }
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;
procedure WMMove(var Message: TMessage);
message WM_MOVE;
procedure CMMouseEnter(var Message: TMessage);
message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage);
message CM_MOUSELEAVE;
procedure WMLButtonDown (Var Message: TWMLButtonDown);
Message WM_LButtonDown;
procedure WMKillFocus (Var Message: TWMKillFocus);
Message WM_KillFocus;
procedure CNCTLCOLORMSGBOX(var Message:TWMCTLCOLORMSGBOX);
message CN_CTLCOLORMSGBOX;
procedure CNCTLCOLORSTATIC(var Message:TWMCTLCOLORSTATIC);
message CN_CTLCOLORSTATIC;

protected
{ Protected declarations }
procedure CreateParams(var Params: TCreateParams);
override;
procedure CreateWnd;override;
proceduredo
Exit;
override;
proceduredo
Enter;
override;
public
{ Public declarations }
constructor Create(AOwner: TComponent);
override;
published
{ Published declarations }
//property TransParent:Boolean read FTransparent write SetTransparent default True ;
end;

procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TTMMemo]);
end;

{ TTMMemo }
procedure TTMMemo.CMMouseEnter(var Message: TMessage);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMMemo.CMMouseLeave(var Message: TMessage);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMMemo.CNCTLCOLOREDIT(var Message: TWMCTLCOLOREDIT);
begin
with Messagedo
begin
SetBkMode(ChildDC,Windows.TRANSPARENT);
Result:=GetStockObject(HOLLOW_BRUSH)
end
end;

procedure TTMMemo.CNCTLCOLORMSGBOX(var Message: TWMCTLCOLORMSGBOX);
begin
Message.Result:=-1;
end;

procedure TTMMemo.CNCTLCOLORSTATIC(var Message: TWMCTLCOLORSTATIC);
begin
Message.Result:=-1;
end;

constructor TTMMemo.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := [csCaptureMouse, csDesignInteractive, csClickEvents,
csSetCaption, csOpaque, csDoubleClicks, csReplicatable, csNoStdEvents];
end;

procedure TTMMemo.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Paramsdo
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 TTMMemo.CreateWnd;
begin
inherited CreateWnd;
SetWindowLong(Parent.Handle, GWL_STYLE,
GetWindowLong(Parent.Handle, GWL_STYLE) and not WS_CLIPCHILDREN);
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle,GWL_EXSTYLE) or WS_EX_TRANSPARENT);
end;

procedure TTMMemo.DoEnter;
var exstyle,stdstyle:longint;
begin
inherited;
StdStyle:= Windows.GetWindowLong(handle, GWL_EXSTYLE);
exStyle:= StdStyle and not WS_EX_TRANSPARENT;
Windows.SetWindowLong(handle, GWL_EXSTYLE, exStyle);
invalidate;
end;

procedure TTMMemo.DoExit;
begin
inherited;
SetCursor(0);
RecreateWnd;
end;

procedure TTMMemo.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 TTMMemo.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
Message.Result := 1;
end;

procedure TTMMemo.WMHScroll(var Message: TWMHScroll);
begin
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMMemo.WMKeyDown(var Message: TWMKeyDown);
begin
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMMemo.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0)
end;

procedure TTMMemo.WMLButtonDown(var Message: TWMLButtonDown);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

{procedure TTMMemo.WMMouseMove(var Message: TWMMouseMove);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;
}
procedure TTMMemo.WMMove(var Message: TMessage);
begin
inherited;
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTMMemo.WMSetText(var Message: TWMSetText);
begin
inherited;
if not (csDesigning in ComponentState) then
PostMessage(Handle,TMWM__SpecialInvalidate,0,0)
end;

procedure TTMMemo.WMVScroll(var Message: TWMVScroll);
begin
SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
inherited;
PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

end.
 
多人接受答案了。
 
后退
顶部