DELPHI中如何让FORM窗体透明,只显示控件?
DELPHI中如何让FORM窗体透明,只显示控件?
分享到:
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理 回复次数:7
largewang
largewang
largewang
等级:Blank
#1 得分:5 回复于: 2002-12-17 13:58:37
procedure TForm1.FormCreate(Sender: TObject);
begin
BorderStyle := bsNone;
Brush.Style := bsClear;
end;
//保证你只看的到控件!!!
关注CSDN论坛微博 送CSDN积分大礼包对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理
wzrlover
wzrlover
wzrlover
等级:Blank
#2 得分:12 回复于: 2002-12-17 13:59:32
我想这是你需要的吧:
unit Unit1;
{The transparent form effect is done with Regions.
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...}
interface
uses
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.
与她合影留念,致终将逝去的青春对我有用[1] 丢个板砖[0] 引用 | 举报 | 管理
Rensun
Rensun
Rensun
我试了,两种方法都可以实现,第一种比较简单,请问两种方法有什么区别呢?
(技术上)
用这个方法也可以
在interface的private里加入
PROCEDURE CMEraseBkgnd(var Message:TWMEraseBkgnd);Message WM_ERASEBKGND;
在implemetation里加入
PROCEDURE Tform1.CMEraseBkgnd(var Message:TWMEraseBkgnd);
BEGIN
brush.style:=bsClear;
Inherited;
END;
DELPHI中如何让FORM窗体透明,只显示控件?的更多相关文章
- WPF中获取Hwnd与窗体,Uid获取控件
void MapControl_Loaded(object sender, RoutedEventArgs e) { this.OnApplyTemplate(); CurrentMapChanged ...
- Delphi中实现MDI子窗体(转)
Delphi中实现MDI子窗体 用MDI实现浏览子窗口,具有窗口管理功能,同屏观看多个网页的内容 ① 多文档窗体(MDI) MDI窗体是一种具有主子结构的窗体体系,微软的Word便是其中的一 ...
- Delphi中,除了应用程序主窗口会显示在任务栏上,其它窗口默认都不会显示在任务栏.
Delphi中,除了应用程序主窗口会显示在任务栏上,其它窗口默认都不会显示在任务栏. Delphi中,除了应用程序主窗口会显示在任务栏上,其它窗口默认都不会显示在任务栏.没有MS开发环境中的ShowI ...
- WPF Prism MVVM 中 弹出新窗体. 放入用户控件
原文:WPF Prism MVVM 中 弹出新窗体. 放入用户控件 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_37214567/artic ...
- Winform开发中如何将数据库字段绑定到ComboBox控件
最近开始自己动手写一个财务分析软件,由于自己也是刚学.Net不久,所以自己写的的时候遇到了很多问题,希望通过博客把一些印象深刻的问题记录下来. Winform开发中如何将数据库字段绑定到ComboBo ...
- C#窗体加载和控件加载不同步导致控件闪烁
窗体加载和控件加载不同步导致的控件闪烁现象:// 代码块加在父窗体中的任意位置,解决窗体加载和控件加载不同步导致的控件闪烁问题 protected override CreatePara ...
- 如何在网页中浏览和编辑DWG文件 梦想CAD控件
如何在网页中浏览和编辑DWG文件 梦想CAD控件 www.mxdraw.com 梦想绘图控件5.2 是国内最强,最专业的CAD开发组件(控件),不需要AutoCAD就能独立运行.控件使用VC 201 ...
- WPF中ContextMenu(右键菜单)使用Command在部分控件上默认为灰色的处理方法
原文:WPF中ContextMenu(右键菜单)使用Command在部分控件上默认为灰色的处理方法 问题描述 今天发现如果我想在一个TextBlock弄一个右键菜单,并且使用Command绑定,结果发 ...
- Winform中在使用Dock属性设计页面布局控件的顺序导致页面效果不同的问题
场景 在Winform中进行页面设计时,常使用控件的Dock属性来进行布局调整.但是由于设置属性的顺序问题,导致达不到想要的效果. 比如以下两个控件 下面的控件设置的Dock属性是Bottom,即在页 ...
随机推荐
- elasticsearch启动问题
ES安装完一直启动不了,问题解决. 报错: ERROR: bootstrap checks failed system call filters failed to install; check th ...
- 在模拟器安装测试APP,给指定设备安装APP
1.配置好安卓环境变量,确保adb已连接且可用 2.启动模拟器,通过cmd命令行窗口 输入adb devices,出现设备信息,该设备信息是模拟器的device ID 3.进入APP的存放目录:D:\ ...
- jsp EL运算符
算术运算符 算术运算符 说明 示例 结果 + 加 ${1 + 1} 2 - 减 ${1 - 1} 0 * 乘 ${1 * 2} 2 /或div 除 ${3 / 2} 1.5 %或mod 取余 ${3 ...
- CSS Id 和 Class
id 和 class 选择器 如果你要在HTML元素中设置CSS样式,你需要在元素中设置"id" 和 "class"选择器.直线电机哪家好 id 选择器 id ...
- Shiro学习(15)单点登录
Shiro 1.2开始提供了Jasig CAS单点登录的支持,单点登录主要用于多系统集成,即在多个系统中,用户只需要到一个中央服务器登录一次即可访问这些系统中的任何一个,无须多次登录.此处我们使用Ja ...
- CF1016F 【Road Projects】
思路 可以考虑另一种想法:因为我们发现,答案是肯定不会大于在原来的树上的最短路径的.所以原来的最短路是(有可能的)最大值! 我们把树变成这样,提取出1~n的路径,方便观看撕烤: (它有个我起的名字,叫 ...
- HBase自定义MapReduce
HBase表数据的转移 在Hadoop阶段,我们编写的MR任务分别进程了Mapper和Reducer两个类,而在HBase中我们需要继承的是TableMapper和TableReducer两个类. 目 ...
- Java线程池ThreadPoolExecutor使用和分析
线程池是可以控制线程创建.释放,并通过某种策略尝试复用线程去执行任务的一种管理框架,从而实现线程资源与任务之间的一种平衡. 以下分析基于 JDK1.7 转自: http://www.cnblogs. ...
- 戏说 .NET GDI+系列学习教程(三、Graphics类的应用_验证码扩展)
从别人那拷贝的 #region 定义和初始化配置字段 //用户存取验证码字符串 public string validationCode = String.Empty; //生成的验证码字符串 pub ...
- 19、Page Object 实例
项目目录介绍: CalcuatorPage.java文件代码: package example; import io.appium.java_client.android.AndroidDriver; ...