程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 在Delphi中實現任意形狀的窗體

在Delphi中實現任意形狀的窗體

編輯:Delphi
Form的TEXT:

  object Form1: TForm1
    Left = 192
    Top = 107
    BorderStyle = bsNone
    Caption = 'Form1'
    ClIEntHeight = 348
    ClIEntWidth = 536
    Color = clBtnFace
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    OldCreateOrder = False
    OnCreate = Button1Click
    PixelsPerInch = 96
    TextHeight = 13
    object Button1: TButton
      Left = 392
      Top = 152
      Width = 75
      Height = 25
      Caption = 'Button1'
      TabOrder = 0
      OnClick = Button1Click
    end
    object Button2: TButton
      Left = 432
      Top = 24
      Width = 17
      Height = 17
      Caption = 'Button2'
      TabOrder = 1
      OnClick = Button2Click
    end
    object Button3: TButton
      Left = 448
      Top = 40
      Width = 17
      Height = 17
      Caption = 'Button2'
      TabOrder = 2
      OnClick = Button3Click
    end
    object Button4: TButton
      Left = 464
      Top = 56
      Width = 17
      Height = 17
      Caption = 'Button2'
      TabOrder = 3
      OnClick = Button4Click
    end
  end

  各種不同的事件聲名:

  
    TForm1 = class(TForm)
      Button1: TButton;
      Button2: TButton;
      Button3: TButton;
      Button4: TButton;
      procedure Button1Click(Sender: TObject);
      procedure Button2Click(Sender: TObject);
      procedure Button3Click(Sender: TObject);
      procedure Button4Click(Sender: TObject);
    private
      procedure WMmove(var Message: TWMNCHITTEST); Message WM_NCHITTEST;
      { Private declarations }
    public
      { Public declarations }
    end;

  var
    Form1: TForm1;

  implementation

  {$R *.DFM}

  procedure TForm1.WMmove(var Message: TWMNCHITTEST);
  begin
    Message.Result :=  HTCAPTION;
  end;

  procedure TForm1.Button1Click(Sender: TObject);
  var
  R1,R2,R3,R4,R5: HRGN;
  begin
    R1 := CreateEllipticRgn(0,0,Round(ClientWidth / 2),ClIEntHeight);
    R2 := CreateEllipticRgn(Round(ClientWidth / 2),0,ClientWidth,ClIEntHeight);
    R3 := CreateEllipticRgn(Round(ClientWidth / 4 ),Round(ClientHeight / 4 *3),Round(ClientWidth / 4 *3),ClIEntHeight);
    R4 := CreateRectRgn(0,0,0,0);
    R5 := CreateRectRgn(0,0,0,0);
    CombineRgn(R4,R2,R1,RGN_or);
    CombineRgn(R5,R4,R3,RGN_or);

    SetWindowRGN(Handle,R5,True);
    DeleteObject(R1);
    DeleteObject(R2);
    DeleteObject(R3);
    DeleteObject(R4);
    DeleteObject(R5);
  end;

  procedure TForm1.Button2Click(Sender: TObject);
  begin
    SendMessage(Handle,WM_SYSCOMMAND,SC_MINIMIZE,0);
  end;

  procedure TForm1.Button3Click(Sender: TObject);
  begin
    SendMessage(Handle,WM_SYSCOMMAND,SC_DEFAULT,0);
  end;

  procedure TForm1.Button4Click(Sender: TObject);
  begin
    Application.Terminate;
  end;

  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved