For forums, blogs and more please visit our
Developer Tools Community.
By: Corbin Dunn
Abstract: How to make transparent portions on your window with Delphi.
Download the sample source code and project for this article.
You may have seen some windows that have transparent portions, and wonder how you can do that in Delphi. It is quite easy, and there are several different ways to achieve the affect such as below:
RgnAll, RgnCtrl: HRGN;
RgnAll := 0;
for I := 0 to ControlCount - 1 do
with Controls[I] do
if Visible then
// Create a region for each given visible control
RgnCtrl := CreateRectRgn(Left, Top, Left + Width, Top + Height);
// Combine the region with all previous ones, if available
if (RgnCtrl <> 0) and (RgnAll <> 0) then
CombineRgn(RgnAll, RgnAll, RgnCtrl, RGN_OR);
RgnAll := RgnCtrl; // This is the first region being created
// Now, set the RgnAll as what we see for the Window
if RgnAll <> 0 then
From SetWindowRgn in the help file:
"After a successful call to SetWindowRgn,
the operating system owns the region specified
by the region handle hRgn. The operating system
does not make a copy of the region. Thus, you
should not make any further function calls with
this region handle. In particular, do not close
this region handle."
So don't call DeleteObject on RgnAll after using
it for SetWindowRgn (thanks to Richard Albury for
pointing this out!) A previous version of this article
made this mistake.
SetWindowRgn(Handle, RgnAll, True);
procedure TForm1.GenericMouseMove(Sender: TObject; Shift: TShiftState; X,
// If the control wasn't moved, then exit right away
if (X - LastX = 0) and (Y - LastY = 0) then Exit;
// Move the control
with (Sender as TControl) do
Left := Left + (X - LastX);
Top := Top + (Y - LastY);
(Sender as TControl).Repaint;
Could not retrieve comments. Please try again later.
Download Delphi 10 now!
Webinars on demand!
More social media choices:
Delphi on Google+
@RADTools on Twitter
Server Response from: ETNASC03