Solved

Multiple nested panels resize problem

Posted on 2002-05-21
15
914 Views
Last Modified: 2010-04-04
There is a strange problem with panels resizing when thre are many (10-40) nested panels (TPanel) with Align=alClient.

The problem - when form with the panels is resized, not all the panels adjust their size.

The number of panels needed to see the problem vary on different computers.

Is this Delphi or Windows problem? Does anybody know a solution?

Simple demonstration of the problem - compile and run a project with following form, set the value in edit box to 20 or 30, press Refresh and then resize the form (enlarge it).

The form code is :
-----------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Spin, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    btnRefresh: TButton;
    se: TSpinEdit;
    procedure btnRefreshClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.btnRefreshClick(Sender: TObject);
var
  i : integer;
  NewPane,
  Pane : TPanel;
begin
  with Panel1 do for i:= 0 to ControlCount - 1 do
    Controls[i].Free;
   
  Pane:= Panel1;
  for i:= 2 to se.Value do begin
    NewPane:= TPanel.Create(Pane);
    with NewPane do begin
      Caption:= 'Nesting level = ' + IntToStr(i);
      Align:= alClient;
      BorderWidth:= 2;
      BevelWidth:= 2;
      Parent:= Pane;
    end;
    Pane:= NewPane;
  end;
end;

end.
-----------------------

The .dfm is :
-----------------------
object Form1: TForm1
  Left = 385
  Top = 23
  Width = 595
  Height = 380
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 587
    Height = 289
    Align = alTop
    BevelWidth = 3
    BorderWidth = 2
    Caption = 'Panel1'
    TabOrder = 0
  end
  object btnRefresh: TButton
    Left = 56
    Top = 312
    Width = 75
    Height = 25
    Caption = 'Refresh'
    TabOrder = 1
    OnClick = btnRefreshClick
  end
  object se: TSpinEdit
    Left = 160
    Top = 312
    Width = 121
    Height = 22
    MaxValue = 222
    MinValue = 2
    TabOrder = 2
    Value = 20
  end
end
-----------------------

0
Comment
Question by:rpo
  • 7
  • 3
  • 2
  • +3
15 Comments
 
LVL 3

Expert Comment

by:tongalite
ID: 7024185
Hi
 
I just imported your demo into D3 Pro...
It works perfectly :)

All the panels are resized as they should be (nesting level 0 to 35)
No problem.

T.

0
 
LVL 1

Author Comment

by:rpo
ID: 7024208
Hmm, i tested it in D4 and D6 - there is a problem.

What Windows did you test on?
0
 
LVL 1

Author Comment

by:rpo
ID: 7024213
Can you send me the exe compiled in D3, please?
E-mail : rpo@crosswinds.net
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 3

Expert Comment

by:tongalite
ID: 7024392
Hi rpo,

The file is sent :)
T
0
 
LVL 1

Author Comment

by:rpo
ID: 7024440
Thanks a lot, tongalite.

I check it in W2K - it works wrong with your exe too. Probably, it's OS problem, not Delphi.

Thank you, anyway.

Just to make clear what i'm talking about - here is the screenshot : http://t2.technion.ac.il/~sromanp/nestedpanels.jpg
0
 
LVL 3

Expert Comment

by:tongalite
ID: 7024545
Hi again,

I looked at your screenshot and I see what you mean. No, It works fine for me (as it should do)???
Must be your OS.
I mailed you a screenshot.
T.
0
 
LVL 1

Author Comment

by:rpo
ID: 7036635
Increased point.
0
 
LVL 1

Author Comment

by:rpo
ID: 7110094
After some investigation I see that inner panels do not receive the WM_PAINT message and if I force them to receive the message (usng SendMessage from the WMPaint method of outer panels) they do run the Paint code, but nothing happens on the screen.

Does Win2K have any limitations on number of "active" device contexts (or whatever)?
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 7110101
Perhaps the problem is in the order you set the properties. Try to set the Parent the first thing after creation (and Align last thing, just in case):

 Pane:= Panel1;
 for i := 2 to se.Value do
 begin
   NewPane:= TPanel.Create(Pane);
   with NewPane do
   begin
     Parent:= Pane;
     Caption:= 'Nesting level = ' + IntToStr(i);
     BorderWidth:= 2;
     BevelWidth:= 2;
     Align:= alClient;
   end;
   Pane:= NewPane;
 end;

Not tested.
0
 
LVL 1

Author Comment

by:rpo
ID: 7110117
Well, this is code only demonstrates the problem. In actual application the panel are not created the same way (they are not created dynamically at all), but the problem still exists.

Anyway, I tried you suggestion - it doesn't help :(.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7110125
listening . . . trying later
0
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 500 total points
ID: 7110185
I gave it a try and it works fine for me ...
ofcourse when this code applied :))

procedure ResizePanel(Panel: TPanel);
var msg: TMessage;
    I: Integer;
begin
     with Panel do
     begin
       FillChar(msg, SizeOf(msg), 0);
       msg.Msg:=WM_SIZE;
       WindowProc(msg);
       Parent.Invalidate;
     end;
     Application.ProcessMessages;

     // now resize the child panels
     for I:=0 to Panel.ControlCount-1 do
         if Panel.Controls[I] is TPanel then
            ResizePanel(TPanel(Panel.Controls[I]));
end;

procedure TForm1.FormResize(Sender: TObject);
begin
     ResizePanel(Panel1);
end;


might be a bit slow but it works (tried up to 80 panels, more wouldn't fit the screen :))
0
 
LVL 2

Expert Comment

by:Felixin
ID: 7110593
Just a smile:

Why don't you like it?. It looks very nice your screenshot.
0
 
LVL 2

Expert Comment

by:Felixin
ID: 7110600
Just a smile:

Why don't you like it?. It looks very nice your screenshot.
0
 
LVL 1

Author Comment

by:rpo
ID: 7111209
Thanks a lot Lee_Nover!

Your answer works fine and does the job, although a bit slow (but it's ok).

It took some time to make it fit in the real application (ActiveXes, panels, embedded forms, etc.) but it works.

You get all the points. 500 here and another 300 in  http://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20316349 . Just put some comment there so I can accept it as the answer.

Although we have a nice workaround, it's still interesting why the original Delphi code does not work.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 144
Dev Express grid collapse 2 45
Tembedded WB animatid gifs not animated on some pcs 2 80
firemonkey keyboard covers the controls 1 26
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question