Topic: Hiding a panel and resizing form

I have a resizable form with a vertical splitter and two panel.

When panel1 is not visible (on click of hide panel1 button) I like the form resize - width reduced as much as hidden panel width. When panel1 shown then form width increased as much as panel1 width - original state.


var Splitter : TSplitter;

// Form1 Vertical Splitter
procedure Form1_OnShow (Sender: string; Action: string);
begin
Form1.Panel1.Align := alLeft;
Splitter := TSplitter.Create(Form1);
Splitter.left := 200;
Splitter.height := 350;
Splitter.Parent := Form1;
Splitter.Align := alLeft;
Splitter.Width := 8;
Splitter.Beveled := True;
Form1.Panel2.Align := alClient;
end;

// SHOW / HIDE LEFT PANEL /////////////////////////
procedure Form1_btnHideLeftPanel_OnClick (Sender: TObject; var Cancel: boolean); // Hide <<
begin
Form1.Panel1.Visible := False;
Form1.btnShowLeftPanel.Visible := True;
Form1.btnHideLeftPanel.Visible := False;
//Splitter.TSplitter.Visible := False (Form1);
//Form1.Width := - Form1.Panel1.Width;
end;

procedure Form1_btnShowLeftPanel_OnClick (Sender: TObject; var Cancel: boolean); // Show >>
begin
Form1.Panel1.Visible := True;
Form1.btnShowLeftPanel.Visible := False;
Form1.btnHideLeftPanel.Visible := True;
//Splitter.TSplitter.Visible := True (Form1);
//Form1.Width := + Form1.Panel1.Width;
end;

Please see the attached sample project if needed.

Post's attachments

Attachment icon Hide and Resize.zip 4.89 kb, 392 downloads since 2018-01-06 

Adam
God... please help me become the person my dog thinks I am.

Re: Hiding a panel and resizing form

Hi Adam,
My questions are more about design rather than how you might code it.
1.  Does Form1 (with Panel1 hidden) shift to the centre (ie BETWEEN Panel1 and Panel2) or shift all the way to the right (to Panel2's position)?
2.  If Form1 calls Form2, where is Form2 positioned?  In the centre of Form1 if Form1 is full size or in the centre of Panel2 if Form1 is reduced size?
3.  Your example has no objects that are not part of either Panel1 or Panel2, but in the real world, is that likely? - for example, Form1 has a full width title displaying the name of your application.  What do you do when Form1 is reduced in size? - do you display half the title, lose the title completely or move the title and reduce it by half so that it fits (perhaps having to change font size at the same time)?  The combinations (and complexity) are significant.
I understand why you might want to hide parts of the screen (panels etc) but I think most of the people that I've written applications for would find it distracting to have forms that changed size and location depending on what they were doing.
Derek.

3 (edited by AD1408 2018-01-06 15:32:02)

Re: Hiding a panel and resizing form

Hi Derek,


Thank you very much for having a look at my question.........


1.  Does Form1 (with Panel1 hidden) shift to the centre (ie BETWEEN Panel1 and Panel2) or shift all the way to the right (to Panel2's position)?

Form doesn't move or shift, just shrinks (width in this case) towards left as much as panel1 width size.


2.  If Form1 calls Form2, where is Form2 positioned?  In the centre of Form1 if Form1 is full size or in the centre of Panel2 if Form1 is reduced size?

It's intended use was for sub forms, no additional forms called from it.
However, if it's used on form1 then as usual MVD defaults or custom form screen position properties would apply. If form2 opened while form1 shrinked (panel1 is hidden) then form2 would appear not exactly on form1 center but somewhere over form1. No additional coding needed for shifting subsequent forms. It doesn't have to appear exact on center of form1.


3.  Your example has no objects that are not part of either Panel1 or Panel2, but in the real world, is that likely? - for example, Form1 has a full width title displaying the name of your application.  What do you do when Form1 is reduced in size? - do you display half the title, lose the title completely or move the title and reduce it by half so that it fits (perhaps having to change font size at the same time)?  The combinations (and complexity) are significant.

Object placements will be taken care on form design stage, taking into account shrinkage. On such forms there cannot be any object width bigger than visible (after hiding) part of the form and anchoring needs to be used appropriately.


At this stage, all I'm asking for a script/code that will sub tthe panel1 width size and shrink the form accordingly and opposite when panel1 shown onclick.
I'm not sure if it's possible but, it'd be nice to have splitter bar hidden too when panel1 is hidden.


Ps/. I know how to show hide and resize the form, when form is static, without sizing and splitter bar. However, on sizeable form with splitter bar I fail.

Adam
God... please help me become the person my dog thinks I am.

Re: Hiding a panel and resizing form

Hi Dmitry,


Could you correct the following couple of line please?

procedure Form1_btnHideLeftPanel_OnClick (Sender: TObject; var Cancel: boolean); // Hide <<
begin
//Form1.Width := - Form1.Panel1.Width;
end;

procedure Form1_btnShowLeftPanel_OnClick (Sender: TObject; var Cancel: boolean); // Show >>
begin
//Form1.Width := + Form1.Panel1.Width;
end;

What I'm trying to achieve is to;
on a sizable form with a vertical splitter, re-size the window according to panel visibility.

Adam
God... please help me become the person my dog thinks I am.

Re: Hiding a panel and resizing form

Corrected lines are as follows:



Form1.Width := Form1.Width - Form1.Panel1.Width;

Form1.Width := Form1.Width + Form1.Panel1.Width;

Re: Hiding a panel and resizing form

Hi EHW,


Thank you so much...................
Looks like my single cell brain missed form1.width bit.

Adam
God... please help me become the person my dog thinks I am.