Recent

Author Topic: Sizable TPanel  (Read 5668 times)

arneolav

  • Full Member
  • ***
  • Posts: 195
    • ElTranslador
Sizable TPanel
« on: April 24, 2018, 11:29:08 pm »
Hi!
I'm devloping an MDI like application using some panels inside a form.
The panels contains TstringGrid's and  TChart's.

The components inside the panels have anchors bottom, left.
This leavs a field like a form's titlebar in top of the panel. (To click and move the panel)

I can move the panels (Thanks to KpjComp)
I can have all panels resized on form resize (thanks to RAW)
All this seems to work well.

My final problem is resize any of the TPanel's by mouse by click on the panel border.

I'v been looking for a sizable panel as i had in Delphi, but can't find any.
And this have to be an application not only for windows, then Messages are not a solution.
Any idea?

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil,
  9.  
  10.   Forms, Controls, Graphics,
  11.   Dialogs, ExtCtrls,
  12.   Grids, TAGraph, types;
  13.  
  14. type
  15.  
  16.   { TPanel }
  17.  
  18.   TPanel = class(ExtCtrls.TPanel)
  19.   protected
  20.     isMouseDown:boolean;
  21.     LastPos:TPoint;
  22.     procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
  23.     procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
  24.     procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
  25.     procedure Click; override;
  26.  
  27.     procedure Panel1Resize(Sender: TObject);
  28.   end;
  29.  
  30.   { TForm1 }
  31.  
  32.   TForm1 = class(TForm)
  33.     Chart1: TChart;
  34.     Panel1: TPanel;
  35.     Panel2: TPanel;
  36.     Panel3: TPanel;
  37.     Panel4: TPanel;
  38.     StringGrid1: TStringGrid;
  39.     procedure FormResize(Sender: TObject);
  40.  
  41.  
  42.   private
  43.     { private declarations }
  44.     lastPos:TPoint;
  45.     isMouseDown:boolean;
  46.  
  47.     Procedure Arrange4Panels(pnl1, pnl2, pnl3, pnl4: TPanel;
  48.                                 iBorder: Integer);
  49.   public
  50.     { public declarations }
  51.   end;
  52.  
  53. var
  54.   Form1: TForm1;
  55.  
  56. implementation
  57.  
  58. {$R *.lfm}
  59.  
  60. { TForm1 }
  61.  
  62. procedure TForm1.FormResize(Sender: TObject);
  63. begin
  64.     Arrange4Panels(Panel1, Panel2, Panel3, Panel4, 20);
  65. end;
  66.  
  67. Procedure TForm1.Arrange4Panels(pnl1, pnl2, pnl3, pnl4: TPanel;                 // Thanks RAW
  68.                                 iBorder: Integer);
  69.   Var
  70.    iX, iY: Integer;
  71.  Begin
  72.   iX:= (ClientWidth  - 3*iBorder) Div 2;
  73.   iY:= (ClientHeight - 3*iBorder) Div 2;
  74.  
  75.   pnl1.SetBounds(iBorder, iBorder, iX, iY);
  76.   pnl2.SetBounds(iBorder*2 +iX, iBorder, iX, iY);
  77.   pnl3.SetBounds(iBorder, iBorder*2 +iY, iX, iY);
  78.   pnl4.SetBounds(pnl2.Left, pnl3.Top, iX, iY);
  79.  End;
  80.  
  81.  
  82.  
  83. { TPanel }
  84. procedure TPanel.Panel1Resize(Sender: TObject);
  85. begin
  86.   with Sender as TPanel do
  87.   begin
  88.        // Something here
  89.   end;
  90. end;
  91.  
  92.  
  93.  
  94.  
  95. procedure TPanel.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  96. begin
  97.   inherited MouseDown(Button, Shift, X, Y);
  98.   isMouseDown := true;
  99.   LastPos := ClientToScreen(point(X, Y));
  100. end;
  101.  
  102. procedure TPanel.MouseMove(Shift: TShiftState; X, Y: Integer);
  103. var
  104.   newRect:TRect;
  105.   newPos:TPoint;
  106. begin
  107.   inherited MouseMove(Shift, X, Y);
  108.   newPos := ClientToScreen(point(x,y));
  109.   if isMouseDown then
  110.   begin
  111.     newRect := BoundsRect;
  112.     OffsetRect(newRect, newPos.x-LastPos.x, NewPos.Y-LastPos.Y);
  113.     BoundsRect := newRect;
  114.   end;
  115.   LastPos := newPos;
  116. end;
  117.  
  118. procedure TPanel.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  119.   Y: Integer);
  120. begin
  121.   inherited MouseUp(Button, Shift, X, Y);
  122.   isMouseDown := false;
  123. end;
  124.  
  125. procedure TPanel.Click;
  126. begin
  127.   inherited Click;
  128.   BringToFront;
  129. end;
  130.  
  131.  
  132. end.
« Last Edit: April 24, 2018, 11:33:40 pm by arneolav »
Win XP, Win7, Win 10, Win 11, win64 , Lazarus 3.0RC1
Delphi/DevExpress

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Sizable TPanel
« Reply #1 on: April 25, 2018, 03:14:55 am »
you are looking for a form inside a form...

I do this myself..

 Make the form at design time but not autocreate, at runtime, create it and set the parent of the form
to show.

 It will show inside that parent and have all the properties of the form, caption, icons, sizeable etc.
 You can have many of these same forms being parented.



The only true wisdom is knowing you know nothing

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Sizable TPanel
« Reply #2 on: April 25, 2018, 05:08:37 am »
There is a TcyResizer (Cindy Components) and you can take a look at the source from CodeTyphon or extract it like @JD did ...

Ask him... maybe you are lucky and he's kind enough and let you use his unit or package.   :)

There are a lot of DELPHI examples out there but then you need LCLIntf I guess and I don't know if this will work on Linux...
Of course you can exchange that part and use SetBounds, but then you have to do it all by yourself...  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

arneolav

  • Full Member
  • ***
  • Posts: 195
    • ElTranslador
Re: Sizable TPanel
« Reply #3 on: April 25, 2018, 09:52:58 pm »
Thanks!

The simplest way seems to be jamie's "form inside a form".
I'll try it first.
Win XP, Win7, Win 10, Win 11, win64 , Lazarus 3.0RC1
Delphi/DevExpress

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Sizable TPanel
« Reply #4 on: April 25, 2018, 10:59:23 pm »
You could also give the JVCL components a try, I recently ported their TJvMovableBevel to Lazarus. Yes it is a bevel, but your question motivated me to adapt the code to a panel, and now there's a TJvMovablePanel as well.

JVCL - this huge library with hundreds of components may appear scary, but it in this case it is easy: the unit is selfcontained and does not need any other JVCL unit. I added it as an attachment.

If you are interested in other JVCL components: Since this is work in progress I did not yet submit the current version to OPM, and you'll need svn to get the trunk version. Or download the CCR snapshot and extract only the folder components/jvcllaz from the zip file. https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/jvcllaz/

See also: http://wiki.freepascal.org/JVCL_Components#JvCtrls

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
Re: Sizable TPanel
« Reply #5 on: April 26, 2018, 09:52:27 am »
My final problem is resize any of the TPanel's by mouse by click on the panel border.
Try to make so
http://forum.lazarus.freepascal.org/index.php/topic,38824.msg266579.html#msg266579
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

arneolav

  • Full Member
  • ***
  • Posts: 195
    • ElTranslador
Re: Sizable TPanel
« Reply #6 on: April 26, 2018, 05:45:52 pm »
I know some of the  JVCL components rather well from use in Delphi7.
Are they still "windows only"?
I dowloaded all the components from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/jvcllaz/
and I'll hava a look at it.
I can tell; what I missed in the beginning of using Lazarus was exactly all the JVCL components.
...

I downladed http://forum.lazarus.freepascal.org/index.php/topic,38824.msg266579.html#msg266579.
But seems I'v to update my Lazarus as I'm missing Application.Scaled
I tried update some time ago, but run into trouble with some component(s). May be they are fixed now.

Seems i'v a lot to do now.

Win XP, Win7, Win 10, Win 11, win64 , Lazarus 3.0RC1
Delphi/DevExpress

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Sizable TPanel
« Reply #7 on: April 26, 2018, 10:17:48 pm »
@zoltanleo
Thanks, works nice on W7x64...
Maybe you can enhance it by controlling the size during the resize progress ...

Now it's possible to resize the panel beyond the underlying form. Not a big deal but on a form that's not sizeable you probably get some trouble...  :)

EDIT:
Yeah, there is an OnResize event, I overlooked that ...  :)

@wp:
Thanks, TJvMovablePanel works great too... nice to have this out of the box...  :)
« Last Edit: April 26, 2018, 10:50:21 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Sizable TPanel
« Reply #8 on: April 26, 2018, 11:22:49 pm »
I know some of the  JVCL components rather well from use in Delphi7.
Are they still "windows only"?
No - at least those which you can find in the CCR port should be cross-platform (although I only test on Windows and Linux-gtk2/qt).

But seems I'v to update my Lazarus as I'm missing Application.Scaled
Sorry for that. I am working with Lazarus trunk which adds this line to the project file, and only sporadically test back to Laz 1.6.4.

I tried update some time ago, but run into trouble with some component(s). May be they are fixed now.
Please report details. In this one-man activity most of the testing burdon must be loaded on the user...

Maybe a word on the package structure which is a bit unusual. The original JVCL library, I think, comprises several hundred components. Therefore I want to keep the original package structure which puts only a limited number of packages into each package. And I try to keep the packages independent of each other as much as possible because I do not want to force the user to install 700 components because he just needs the TJvMovablePanel. Therefore, installation may appear to be a nightmare. Always follow this strategy: Compile the core packages JvCoreLazR and JvCoreLazD - the suffixes "R" and "D" refer to ruintime and designtime packages. the core packages are needed by all others. Then, using the wiki article http://wiki.freepascal.org/JVCL_Components  find the package in which the components of interest at contained, compile the corresponding runtime package and install the designtime package.

When the current port has reached a stable state I will submit the JVCL port to the Online Package Manager which will make installation much easier: Just check the packages you want and start the installation.

arneolav

  • Full Member
  • ***
  • Posts: 195
    • ElTranslador
Re: Sizable TPanel
« Reply #9 on: April 27, 2018, 08:49:34 pm »
Hi!
I'v installed Laz 1.8.2. 64 bit. Win10.

JVCL core packages JvCoreLazR and JvCoreLazD did compile OK.

Tried to install JvXPbar as I'm used to it.
Error -> ucmdbox.pas(1399,13) Error: Identifier not found "UTF8Length"

Tested some other components, same error.
Win XP, Win7, Win 10, Win 11, win64 , Lazarus 3.0RC1
Delphi/DevExpress

balazsszekely

  • Guest
Re: Sizable TPanel
« Reply #10 on: April 27, 2018, 09:07:33 pm »
@wp
I did try to install JVCLLaz from OPM and it gave me the following error(attachment). I'm 100% sure that the package worked in the past(version 1.0.2.0).

My system: Win7, Laz trunk, FPC 3.0.4
« Last Edit: April 27, 2018, 09:09:17 pm by GetMem »

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Sizable TPanel
« Reply #11 on: April 27, 2018, 10:32:45 pm »
Please refresh the OPM repository, the last "official" version is 1.0.4 which was released just to fix this bug (r6157) - it is offered in the external ccr repository.

balazsszekely

  • Guest
Re: Sizable TPanel
« Reply #12 on: April 27, 2018, 10:48:43 pm »
Quote
Please refresh the OPM repository
OK. Done.

Quote
the last "official" version is 1.0.4 which was released just to fix this bug (r6157) - it is offered in the external ccr repository.
Works fine now(1.0.4).

arneolav

  • Full Member
  • ***
  • Posts: 195
    • ElTranslador
Re: Sizable TPanel
« Reply #13 on: May 06, 2018, 03:10:36 pm »
A result of mine "investigation" is to be found here: http://forum.lazarus.freepascal.org/index.php?topic=41168.new#new
Win XP, Win7, Win 10, Win 11, win64 , Lazarus 3.0RC1
Delphi/DevExpress

 

TinyPortal © 2005-2018