在窗体上放一个按钮,然后试试这个:
procedure TForm1.Button1Click(Sender: TObject);
var hr1,hr2,hr3,hr4,hr5 : HRGN;
begin
if button1.Caption='Get Holes' then
begin
hr1 := CreateRectRgn(0, 0, form1.Width, form1.height);
hr2 := CreateRectRgn(25, 30, 155, 105);
hr3 := CreateRectRgn(165, 30, 295, 105);
hr4 := CreateRectRgn(25, 115, 155, 190);
hr5 := CreateRectRgn(165, 115, 295, 190);
CombineRgn(hr1, hr1, hr2, RGN_DIFF);
CombineRgn(hr1, hr1, hr3, RGN_DIFF);
CombineRgn(hr1, hr1, hr4, RGN_DIFF);
CombineRgn(hr1, hr1, hr5, RGN_DIFF);
SetWindowRgn(Form1.Handle, hr1, True);
button1.Caption:='No Holes';
end
else if button1.Caption='No Holes' then
begin
hr1:=CreateRectRgn(0, 0, form1.Width, form1.Height);
SetWindowRgn(form1.Handle, hr1, true);
button1.Caption:='Get Holes';
end;
end;
跟顶层的Redbreast方法一致,主要就是使用
CreateRectRgn和SetWindowRgn两个函数,但是如果比较复杂的形状,可以使用
CombineRgn来对不同的形状的交集进行集合操作,出现不同的效果。