How set Panel position always above of hole region?

225 views Asked by At

I have a code that creates a hole in Form using the mouse.

var
 FormRegion, HoleRegion: HRGN;
begin
  FormRegion := CreateRectRgn(0, 0, Form1.Width, Form1.Height);
  HoleRegion := CreateRectRgn(X1, Y1, X2, Y2);

  CombineRgn(FormRegion, FormRegion, HoleRegion, RGN_DIFF);
  SetWindowRgn(Form1.Handle, FormRegion, True);
end;

Now i wish put one Panel (that already have a fixed height) always above of hole region (and with same width of hole) to simulate a title bar, something like this:

enter image description here

How can be made?

1

There are 1 answers

2
Tom Brunberg On

You did not read carefully my request for additional information, so I leave it to you to adjust however you like.

Anyway, I believe your actual question is concerning the alignment of the panel with the transparent region. You probably do not consider that the region calculations with the form window includes the borders, so you have an offset to the right and downwards.

Since the regions are calculated including the borders of the form, you will need a variable ClientOffset: TPoint to hold the values of width of the left border and the height of the top border (incl. title bar of the form).

var
  ClientOffset: TPoint; 

To calculate the ClientOffset you can use the predefined ClientOrigin and the forms Left and Top properties.

ClientOffset.X := Form36.ClientOrigin.X - Form36.Left; // Left border width
ClientOffset.Y := Form36.ClientOrigin.Y - Form36.Top;  // Top border height (incl. title bar)

Then, either subtract ClientOffset from the panels Left and Top properties, or add ClientOffset to the HoleRegions coordinates. The latter being more correct if you use the mouse (and presumably the forms client coordinates) to define the "hole" region