想做一个透明的控件,是带焦点的,比如button, 是透明的,但也可以有焦点,用键盘也可以操作. 网上找的都是基于TGraphiccontrol的,不能有焦点.
我要的是基于TWinControl或TCustomControl的. 给出源码, 测试能用立即给分
我要的是基于TWinControl或TCustomControl的. 给出源码, 测试能用立即给分
解决方案 »
- 我用trayicon实现的托盘,请问如何实现foxmail一样在托盘上自动提示收到邮件1个的功能
- 如何用olecontainer如何打开一个word文挡
- ehlib实现excel中冻结的功能怎么设置?
- IntraWeb使用TIWTemplateProcessorHTML的问题
- 安装Dev ExpressQuantumGrid 4遇到的问题!!
- 100分问一下2个小问题~送分~
- 高分求救,怎么实现金山打字通的跟踪功能??急急急在线等待!
- 在FastReport中如何使用自定义函数?别人说的怎么不对,老报错:undefined symbol "SMALLTOBIG"
- 获取Package里面的结果集
- 打包安装出错的问题!送分!!!!!!!!!!
- 2007-04-03不能转换为int
- 只有强迫才能行吗?
透明的控件, 一般继承自TGraphicControl的
(就是那些没有handle属性, 不能有focus的控件, 如image)
都有Transparent属性. 对TWinControl类的控件, 要实现透明只要完成以下
四步基本上就成了.1.在Create中设定ControlStyle :=ControlStyle - [csOpaque];2. override 它的CreateParams方法, exstyle 里加上WS_EX_TRANSPARENT.3. 修改它的parent的window style, 去掉WS_CLIPCHILDREN.
inherited CreateParams(Params);
with Params do
begin
{ 完全重画 }
Style := Style and not WS_CLIPCHILDREN;
Style := Style and not WS_CLIPSIBLINGS;
{ 增加透明 }
ExStyle := ExStyle or WS_EX_TRANSPARENT;
end;4. 截获WM_ERASEBKGND, 什么都不做直接返回1.(不搽除背景)一般有上面3步能成. 有些控件比如TPanel, 在它的paint中用了fillrect,
所以要实现透明的话还要override 它的paint方法, 自己画.
按钮透明需要进一步处理.
createparams里加上style := style or BS_OWNERDRAW;
然后在WM_DRAWITEM中自己画吧
这个我也看到过,可实际上根本不行的,你自己试试就知道了.
TCustomTransparentControl = class(TCustomControl)
private
FInterceptMouse: Boolean;
protected
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
procedure CreateParams(var Params: TCreateParams); override;
procedure InvalidateControlsUnderneath;
public
constructor Create(AOwner: TComponent); override;
procedure Invalidate; override;
property InterceptMouse: Boolean read FInterceptMouse write FInterceptMouse default False;
end;implementation
{ TCustomTransparentControl }constructor TCustomTransparentControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csOpaque];
Brush.Style := bsClear;
end;procedure TCustomTransparentControl.InvalidateControlsUnderneath;
var
I: Integer;
Invalidating: Boolean;
Control: TControl; procedure DoInvalidate(AControl: TControl);
var
I: Integer;
Control: TControl;
begin
if AControl is TWinControl then
begin
if TWinControl(AControl).HandleAllocated then
with TWinControl(AControl) do
begin
RedrawWindow(Handle, nil, 0, RDW_INVALIDATE or RDW_FRAME);
InvalidateRect(Handle, nil, True);
end;
if (csAcceptsControls in AControl.ControlStyle) then
for I := 0 to TWinControl(AControl).ControlCount - 1 do
begin
Control := TWinControl(AControl).Controls[I];
DoInvalidate(Control);
end;
end else
AControl.Invalidate;
end;begin
Invalidating := False;
if HandleAllocated then
begin
for I := Parent.ControlCount - 1 downto 0 do
begin
Control := Parent.Controls[I];
if Invalidating then
DoInvalidate(Control)
else if Control = Self then
Invalidating := True;
end;
InvalidateRect(Parent.Handle, nil, True);
end;
end;procedure TCustomTransparentControl.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
end;procedure TCustomTransparentControl.WMNCHitTest(var Message: TWMNCHitTest);
begin
if not FInterceptMouse then
Message.Result := HTTRANSPARENT;
end;procedure TCustomTransparentControl.Invalidate;
begin
InvalidateControlsUnderneath;
inherited Invalidate;
end;
到http://bbs.yd153.com搜搜