创建异形窗口[3]
本例效果图:代码文件:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormDblClick(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var rgn: HRGN; begin BeginPath(Canvas.Handle); SetBKMode(Canvas.Handle, TRANSPARENT); Canvas.Font.Size := 56; Canvas.Font.Style := [fsBold]; Canvas.TextOut(12, 12, 'Delphi'); EndPath(Canvas.Handle); rgn := PathToRegion(Canvas.Handle); Self.Color := clRed; SetWindowRgn(Handle, rgn, True); end; procedure TForm1.FormDblClick(Sender: TObject); begin Close; end; end.窗体文件:
object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 206 ClientWidth = 339 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False OnDblClick = FormDblClick PixelsPerInch = 96 TextHeight = 13 object Button1: TButton Left = 136 Top = 112 Width = 75 Height = 25 Caption = 'Button1' TabOrder = 0 OnClick = Button1Click end endposted on 2008-04-30 17:23 万一 阅读(3188) 评论(10) 编辑 收藏