I am trying to resize a borderless form but when I increase the size using the right/bottom side, I get a gap between the border and the old client area that depends of the speed you move the mouse.
The effect is more noticeable when you resize from the left border or even from the bottomleft corner, it's horrible everywhere (I tried with other commercial apps and it happens as well). This effect happens as well when I change to sizable border, but it's not as awful as when I remove form borders
The form layout consists in a top panel doing the title bar function (with some tImages and buttons), and some other panels showing other info (like a memo, other controls, etc)
There's a snip of my code where I capture the mouse button and send a message to windows, but I also tried to do it manually with the similar results
Activating the double buffer for the top panel avoids flickering, but resizing the panel is not synchronized with form resizing, thus appearing a gap, or part of the panel disapearing
procedure TOutputForm.ApplicationEvents1Message( var Msg: tagMSG;
var Handled: Boolean );
const
BorderBuffer = 5;
var
X, Y: Integer;
ClientPoint: TPoint;
direction: integer;
begin
Handled := false;
case Msg.message of
WM_LBUTTONDOWN:
begin
if fResizable then
begin
if fSides = [sTop] then
direction := 3
else if fSides = [sLeft] then
direction := 1
else if fSides = [sBottom] then
direction := 6
else if fSides = [sRight] then
direction := 2
else if fSides = [sRight, sTop] then
direction := 5
else if fSides = [sLeft, sTop] then
direction := 4
else if fSides = [sLeft, sBottom] then
direction := 7
else if fSides = [sRight, sBottom] then
direction := 8;
ReleaseCapture;
SendMessage( Handle, WM_SYSCOMMAND, ( 61440 + direction ), 0 );
Handled := true;
end;
end;
WM_MOUSEMOVE:
begin
// Checks the borders and sets fResizable to true if it's in a "border"
// ...
end; // mousemove
end; // case
end;
How could I avoid that area and/or force windows to be redrawn? I am using Delphi but a generic solution (or in other language) or even a direction to go forward would be fine for me
Thank you in advance
Last time I attempted to manually make a top level window that resizes via WM_SYSCOMMAND and mouse drag, whether involving any nested panels or no, I found the problems were not limited only to flicker.
Even with a bare-TForm without a resizeable border, adding my own resizeable border and handling the mouse down and mouse move and mouse up messages directly proved too problematic. I gave up on the code-approach you are showing here, and instead I found two workable approaches:
use an approach where I take over the painting of the non-client areas. This is what Google Chrome and many other fully-custom windows do. You still have a nonclient area and it's up to you to paint it and handle the non-client and border paint. In other words, it's not truly borderless, but it could all be a single color, if you wanted it to be. Read this help about WM_NCPAINT messages, to get started.
Use a borderless resizeable window that still gets recognized (even without its nonclient area as a resizeable window. Think of a post-it-note-applet. Here is a question I asked a while ago, at the bottom of my question is a fully working demo that provides a smooth flicker free way to have a borderless resizeable window. The underlying technique for the answer was provided by David H.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With