[delphi] 모달 창 띄울 시 배경 효과

2018-04-12

모달 창 띄울 시 배경 효과

  • 모달 창을 띄울 때 BG변화를 줄 수 있는 예
  • 모달 창을 띄우기 전 후에 실행되는 “Application.OnModalBegin”, “Application.OnModalEnd” 이벤트 활용
  • Delphi XE8

code

main.pas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
unit Main;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.AppEvnts, Vcl.StdCtrls;

type
TFMain = class(TForm)
btnModal: TButton;
procedure FormCreate(Sender: TObject);
procedure btnModalClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
protected
procedure OnEventsModalBegin(Sender: TObject);
procedure OnEventsModalEnd(Sender: TObject);
end;

var
FMain: TFMain;

implementation

uses
Screen;

{$R *.dfm}

procedure TFMain.OnEventsModalBegin(Sender: TObject);
begin
ScreenBegin(Self);
end;

procedure TFMain.OnEventsModalEnd(Sender: TObject);
begin
ScreenEnd;
end;

procedure TFMain.btnModalClick(Sender: TObject);
var
f: TForm;
begin
f := TForm.Create(Self);
f.ShowModal;
f.Free;
end;

procedure TFMain.FormCreate(Sender: TObject);
begin
Application.OnModalBegin := OnEventsModalBegin;
Application.OnModalEnd := OnEventsModalEnd;
end;

end.

Screen.pas

  • FScreen.BorderIcons = [bsNone]
  • FScreen.AlphaBlend = True
  • FScreen.AlphaBlendValue = 150
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
unit Screen;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
TFScreen = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

procedure ScreenBegin(f: TForm);
procedure ScreenEnd;

implementation

{$R *.dfm}

var
FScreen: TFScreen;

procedure ScreenBegin(f: TForm);
begin
if FScreen = nil then
FScreen := TFScreen.Create(nil);

FScreen.Top := f.Top;
FScreen.Left := f.Left;
FScreen.Height := f.Height;
FScreen.Width := f.Width;
FScreen.Show;
end;

procedure ScreenEnd;
begin
FScreen.Hide;
end;

initialization

finalization
FScreen.Free;
FScreen := nil;

end.
Tags: delphi