答案 0 :(得分:6)
这很简单。首先,我们需要一个淡化给定位图的例程:
procedure FadeBitmap(ABitmap: TBitmap);
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[word] of TRGBTriple;
var
SL: PRGBTripleArray;
y: Integer;
x: Integer;
begin
ABitmap.PixelFormat := pf24bit;
for y := 0 to ABitmap.Height - 1 do
begin
SL := ABitmap.ScanLine[y];
for x := 0 to ABitmap.Width - 1 do
with SL[x] do
begin
rgbtRed := rgbtRed div 2;
rgbtGreen := rgbtGreen div 2;
rgbtBlue := rgbtBlue div 2;
end;
end;
end;
然后,当我们想要显示模态消息时,我们会创建一个位图' screenshot'我们当前的形式,淡化它,并将其置于表格的所有控件之上:
procedure TForm1.ButtonClick(Sender: TObject);
var
bm: TBitmap;
pn: TPanel;
img: TImage;
begin
bm := GetFormImage;
try
FadeBitmap(bm);
pn := TPanel.Create(nil);
try
img := TImage.Create(nil);
try
img.Parent := pn;
pn.BoundsRect := ClientRect;
pn.BevelOuter := bvNone;
img.Align := alClient;
img.Picture.Bitmap.Assign(bm);
pn.Parent := Self;
ShowMessage('Hello, Faded Background!');
finally
img.Free;
end;
finally
pn.Free;
end;
finally
bm.Free;
end;
end;
提示:如果要在应用程序中显示多个模式对话框,则可能需要重构此操作。为此,请查看TApplicationEvent
的{{1}}和OnModalBegin
个事件。