Recent

Author Topic: Resizing the forum is not working properly  (Read 1168 times)

khichi

  • Newbie
  • Posts: 5
Resizing the forum is not working properly
« on: February 07, 2023, 10:54:02 am »
Hello everyone, I am trying to resize the form / window for which the BorderStyle value is set to bsNone,  On right panel the resize is working as expected, but on left side / panel, the resize does not works as expected, the window flickers on resize and the resize operation is not smooth. Kindly help me to fix this.

I have attached the zip file with code and project settings, however, I am also reproducing the code for left & right panel resize:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.LeftPanelResize(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  2. var
  3.   NewWidth: Integer;
  4. begin
  5.  
  6.   NewWidth := (Left+Width) - Mouse.CursorPos.X + RightPanel.Width;
  7.   if (NewWidth > 60) then
  8.   begin
  9.     Left := Left + Width - NewWidth;
  10.     Width := NewWidth;
  11.   end;
  12. end;
  13.  
  14.  
  15.  
  16.  
  17. procedure TForm1.RightPanelResize(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  18. var
  19.   NewWidth: Integer;
  20. begin
  21.   if DoResize and (ssLeft in Shift) then
  22.   begin
  23.     SetBounds(Left, Top, Width + X - DownX, Height);
  24.     //DownX := X;
  25.   end;
  26.  
  27. end;      
  28.  

Thanks in advance for you help.

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: Resizing the forum is not working properly
« Reply #1 on: February 07, 2023, 09:15:08 pm »
Hello, read my previous post, it may come in handy. Regards

https://forum.lazarus.freepascal.org/index.php/topic,60383.msg451366.html#msg451366


KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Resizing the forum is not working properly
« Reply #2 on: February 08, 2023, 12:00:56 am »
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows ,
  9.   Classes , SysUtils , Forms , Controls , Graphics , Dialogs , ExtCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     pnlRight: TPanel;
  17.     pnlLeft: TPanel;
  18.     procedure pnlMouseDown(Sender: TObject; Button: TMouseButton;
  19.       Shift: TShiftState; X , Y: Integer);
  20.     procedure pnlMouseMove(Sender: TObject; Shift: TShiftState; X ,
  21.       Y: Integer);
  22.     procedure pnlMouseUp(Sender: TObject; Button: TMouseButton;
  23.       Shift: TShiftState; X , Y: Integer);
  24.   strict private
  25.   private
  26.  
  27.   public
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.lfm}
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.pnlMouseDown(Sender: TObject; Button: TMouseButton;
  41.   Shift: TShiftState; X , Y: Integer);
  42. begin
  43.   if (Button <> mbLeft) then
  44.     Exit;
  45.   SetCapture(TWinControl(Sender).Handle);
  46. end;
  47.  
  48. procedure TForm1.pnlMouseMove(Sender: TObject; Shift: TShiftState; X ,
  49.   Y: Integer);
  50. var
  51.   newPos: TPoint;
  52.   tmpL: Integer;
  53. begin
  54.   tmpL := Left;
  55.   if ssLeft in Shift then
  56.     begin
  57.       Screen.Cursor := crSizeWE;
  58.       if (Sender = pnlLeft) then
  59.         begin
  60.           GetCursorPos(newPos);
  61.           Left := newPos.X;
  62.           Width := Width - Left + tmpL;
  63.         end
  64.         else
  65.         begin
  66.           newPos := ScreenToClient(Mouse.CursorPos);
  67.           Width := newPos.X;
  68.         end;
  69.       Invalidate;
  70.     end;
  71. end;
  72.  
  73. procedure TForm1.pnlMouseUp(Sender: TObject; Button: TMouseButton;
  74.   Shift: TShiftState; X , Y: Integer);
  75. begin
  76.   if (Button <> mbLeft) then
  77.     Exit;
  78.   Screen.Cursor := crDefault;
  79.   ReleaseCapture;
  80. end;
  81.  
  82. end.
My try, haven't tested yours, neither tried earlier to-do such but this came out. Maybe it help maybe it's crap  :-[
« Last Edit: February 08, 2023, 12:06:44 am by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

khichi

  • Newbie
  • Posts: 5
Re: Resizing the forum is not working properly
« Reply #3 on: February 08, 2023, 02:01:10 pm »
Thanks Pe3s & KodeZwerg, I have tried the provided solutions but the result is same,

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Resizing the forum is not working properly
« Reply #4 on: February 08, 2023, 05:28:52 pm »
Try the attached project, adapted from yours.

On Windows at least, it shows no flicker.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Resizing the forum is not working properly
« Reply #5 on: February 08, 2023, 05:33:46 pm »
slight mod to your original code, note have made a constant to set minimum size of left right panel.

Code: Pascal  [Select][+][-]
  1. const Min_Panel_Width=60;  
  2.  
  3. procedure TForm1.LeftPanelResize(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  4. begin
  5.   if DoResize and (x >= Min_Panel_Width) and (x<RightPanel.Left) then
  6.   begin
  7.     LeftPanel.Width := x;
  8.     LeftPanel.Invalidate;
  9.   end;
  10. end;
  11.  
  12. procedure TForm1.RightPanelResize(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  13. var Temp_Point:tpoint;
  14.     New_Width:integer;
  15. begin
  16.   if DoResize and (RightPanel.Width>=Min_Panel_Width) then // and (ssLeft in Shift) then
  17.   begin
  18.     Temp_Point:=screentoclient(mouse.CursorPos);
  19.     if Temp_Point.x>LeftPanel.Width then
  20.     begin
  21.       New_Width:=RightPanel.Parent.Width-Temp_Point.x;
  22.       if New_Width<Min_Panel_Width then New_Width:=Min_Panel_Width;
  23.       RightPanel.SetBounds(Temp_Point.x,RightPanel.Top,New_Width,RightPanel.Height);
  24.       RightPanel.Invalidate;
  25.     end;
  26.   end;
  27. end;

ps adjusted your form create tocreate panels with min width

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   BorderStyle := bsNone;
  4.  
  5.   // Create a panel for left side resize
  6.   LeftPanel := TPanel.Create(Self);
  7.   with LeftPanel do
  8.   begin
  9.     Parent := Self;
  10.     Align := alLeft;
  11.     Width := Min_Panel_Width;
  12.     Cursor := crSizeWE;
  13.     OnMouseDown := @FormMouseDown;
  14.     OnMouseMove := @LeftPanelResize;
  15.     OnMouseUp := @FormMouseUp;
  16.     color:=clGreen;
  17.   end;
  18.  
  19.   // Create a panel for right side resize
  20.   RightPanel := TPanel.Create(Self);
  21.   with RightPanel do
  22.   begin
  23.     Parent := Self;
  24.     Align := alRight;
  25.     Width := Min_Panel_Width;
  26.     Cursor := crSizeWE;
  27.     OnMouseDown := @FormMouseDown;
  28.     OnMouseMove := @RightPanelResize;
  29.     OnMouseUp := @FormMouseUp;
  30.     color:=clRed;
  31.   end;
  32.  
  33.   OnResize := @FormResize;
  34. end;                
« Last Edit: February 08, 2023, 05:40:03 pm by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

 

TinyPortal © 2005-2018