At design time, the form looks and acts like any other form...



At runtime though, in OnCreate, the form iterates through its controls and builds up a region corresponding exactly to where the controls are. Anything else is left out...



And when the form is moved, the background shows through and updates properly. Windows does not consider the parts of the form NOT in the region to exist for visual or mousing purposes...



Go back up a second. Compare the locations on screen of the controls at design time and at run time. The controls seem to have moved up just a little. This is because at design time the form has non-client areas but at design time, the title bar and borders are removed. But the window's Left and Top do not move. So the client area moves up and over a little bit. It wasn't important to me here, so I didn't bother to add extra code to handle it.

In this program, I only used the rectangular bounds of the control for the opaque areas. To be extra cool, I would have drawn the TLabel text as a bitmap and then added only the parts that were text to the region and left the gray areas out.

Anyway, here's the important part of the code...

procedure TForm1.FormCreate(Sender: TObject);
  var
    i : integer;
    NewRgn : HRGN;
    ControlRgn : HRGN;
  begin
  NewRgn := CreateRectRgn(0,0,0,0);
  for i := 0 to ControlCount-1 do
    begin
    ControlRgn := CreateRectRgn(Controls[i].left,
                                Controls[i].top,
                                controls[i].left+controls[i].width,
                                Controls[i].top+Controls[i].height);
    CombineRgn(NewRgn,NewRgn,ControlRgn,RGN_OR);
    deleteobject(ControlRgn);
    end;
  setWindowRgn(handle,NewRgn,false);
  end;
Download Project

Peter M. Gruhn