实现窗口从实变透明到消失这是一个例子

此博客展示了一段Windows窗体编程代码,利用定时器控制窗体透明度。代码中定义了窗体类,在窗体创建时设置扩展样式,定时器触发时逐步改变透明度,当透明度减到0后恢复初始值并停止定时器。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; Const WS_EX_LAYERED = $00080000; LMA_COLORKEY = $00000001; LMA_ALPHA = $00000002; var Form1: TForm1; Step: integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var ExtStyle : LongInt; begin Step:=255; ExtStyle := GetWindowLong(Handle, GWL_EXSTYLE); SetWindowLong(Handle, GWL_EXSTYLE, ExtStyle or WS_EX_LAYERED); end; procedure TForm1.Timer1Timer(Sender: TObject); begin if Step>0 then begin Step:=Step-10; SetLayeredWindowAttributes(Handle, RGB(0,0,0), Step, LMA_ALPHA or LMA_COLORKEY); end else begin SetLayeredWindowAttributes(Handle, RGB(0,0,0), 255, 1); Timer1.Enabled:=False; end; end; end.

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值