DELPHI中如何让FORM窗体透明,只显示控件?
解决方案 »
- 怎么POST此格式的数据类型啊。
- delphi Business Skin Form 的bsskincombobox select事件!
- 如何实现网页自动填写
- 请问TSHFileOpStruct这个类要使用那个包
- 有没有办法编程控制MU最新版0。96W里的鼠标?
- Form的OnKeyDown事件疑问。
- 谁能告诉我新中大的待遇怎么样?
- 关于改变TCheckListBox显示的问题,在线给分!!!
- 我是delphi初学者!在窗口上放置了ADOConnection控件、ADOTable控件、DataSource控件和DBGrid控件,通过属性的设置,DBGrid已经显示了数据,当运行时却出错,是不是要在窗口创建的事件中写一些代码?请问如何来写?
- 大侠,怎样做出像Win98 “开始菜单”一样的菜单呢?
- 过程声明问题,我想声明一个过程,它的参数是一个过程,需要怎么生命呢?
- corba程序设计的问题?
begin
BorderStyle := bsNone;
Brush.Style := bsClear;
end;
//保证你只看的到控件!!!
First create a region that encompasses the entire form.
Then, find the client area of the form (Client vs. non-Client) and
combine with the full region with RGN_DIFF to make the borders
and title bar visible. Then create a region for each of the
controls and combine them with the original (FullRgn) region.}{From various posts in the newsgroups - based on some famous
author I'm sure, but I first saw the post by Kerstin Thaler...}interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Button2: TButton;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
procedure DoVisible;
procedure DoInvisible;
public
{ Public declarations }
end;var
Form1: TForm1;
FullRgn, ClientRgn, CtlRgn : THandle;implementation{$R *.DFM}procedure TForm1.DoInvisible;
var
AControl : TControl;
A, Margin, X, Y, CtlX, CtlY : Integer;
begin
Margin := ( Width - ClientWidth ) div 2;
//First, get form region
FullRgn := CreateRectRgn(0, 0, Width, Height);
//Find client area region
X := Margin;
Y := Height - ClientHeight - Margin;
ClientRgn := CreateRectRgn( X, Y, X + ClientWidth, Y + ClientHeight );
//'Mask' out all but non-client areas
CombineRgn( FullRgn, FullRgn, ClientRgn, RGN_DIFF ); //Now, walk through all the controls on the form and 'OR' them
// into the existing Full region.
for A := 0 to ControlCount - 1 do begin
AControl := Controls[A];
if ( AControl is TWinControl ) or ( AControl is TGraphicControl )
then with AControl do begin
if Visible then begin
CtlX := X + Left;
CtlY := Y + Top;
CtlRgn := CreateRectRgn( CtlX, CtlY, CtlX + Width, CtlY + Height );
CombineRgn( FullRgn, FullRgn, CtlRgn, RGN_OR );
end;
end;
end;
//When the region is all ready, put it into effect:
SetWindowRgn(Handle, FullRgn, TRUE);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
//Clean up the regions we created
DeleteObject(ClientRgn);
DeleteObject(FullRgn);
DeleteObject(CtlRgn);
end;procedure TForm1.DoVisible;
begin
//To restore complete visibility:
FullRgn := CreateRectRgn(0, 0, Width, Height);
CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);
SetWindowRgn(Handle, FullRgn, TRUE);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
//We start out as a transparent form....
DoInvisible;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
//This button just toggles between transparent and not trans..
if Button1.Caption = 'Show Form' then begin
DoVisible;
Button1.Caption := 'Hide Form';
end
else begin
DoInvisible;
Button1.Caption := 'Show Form';
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;procedure TForm1.FormResize(Sender: TObject);
begin if Button1.Caption = 'Show Form' then
DoInvisible
else
DoVisible;
end;end.
在interface的private里加入PROCEDURE CMEraseBkgnd(var Message:TWMEraseBkgnd);Message WM_ERASEBKGND;在implemetation里加入
PROCEDURE Tform1.CMEraseBkgnd(var Message:TWMEraseBkgnd);
BEGIN
brush.style:=bsClear;
Inherited;
END;完成,结帖吧
largewang(老王) 的方法虽然可达到透明,但窗体还是存在,无法在窗体上(不是控件上)激活后面的应用程序,就像一块透明的玻璃挡在前面一样.
ad_ad_ad(天上人间) 和largewang(老王)都是一样的意思,也许可以说是同一种方法.