Jump to content

SillyQuestions

Members
  • Content Count

    4
  • Joined

  • Last visited

Everything posted by SillyQuestions

  1. SillyQuestions

    Issue with dynamic panel creation

    I am having issue with panels created once scrolling is needed the width is too wide. I was having another issue with placement incorrect, but I fixed that issue already. There also another issue when resizing the form messes up to the position of panels. unit Unit8; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.UITypes, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ToolWin, Vcl.ComCtrls, Vcl.ExtCtrls; type TForm8 = class(TForm) ScrollBox1: TScrollBox; ToolBar1: TToolBar; Button3: TButton; Button4: TButton; procedure Button3Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form8: TForm8; implementation {$R *.dfm} var ScrollBox: TScrollBox; function GetInScrollBoxTopPos: integer; var I: integer; begin result := 0; for I := 0 to ScrollBox.ControlCount - 2 do if ScrollBox.Controls[I] is TPanel then result := result + TPanel(ScrollBox.Controls[I]).Height + 5; end; type TPanel160 = class panel: TPanel; constructor Create(AOwner: TComponent); end; type TPanel40 = class panel: TPanel; constructor Create(AOwner: TComponent); end; procedure TForm8.Button3Click(Sender: TObject); var panel : TPanel160; begin panel := TPanel160.Create(self) end; { TPanel160 } constructor TPanel160.Create(AOwner: TComponent); begin panel := TPanel.Create(AOwner); panel.Parent := ScrollBox; panel.Color := TColorRec.Red; panel.Caption := ''; panel.Height := 160; panel.Width := ScrollBox.Width - 20; panel.Top := GetInScrollBoxTopPos; panel.Left := 10; panel.Anchors := [akLeft, akRight]; end; { TPanel40 } constructor TPanel40.Create(AOwner: TComponent); begin panel := TPanel.Create(AOwner); panel.Parent := ScrollBox; panel.Color := TColorRec.Blue; panel.Caption := ''; panel.Height := 40; panel.Width := ScrollBox.Width - 20; panel.Top := GetInScrollBoxTopPos; panel.Left := 10; panel.Anchors := [akLeft, akRight]; end; procedure TForm8.Button4Click(Sender: TObject); var panel : TPanel40; begin panel := TPanel40.Create(self) end; procedure TForm8.FormCreate(Sender: TObject); begin ScrollBox := ScrollBox1 end; end. copy.zip
  2. SillyQuestions

    Issue with dynamic panel creation

    EDIT: For it still has issue if I add many panels then resize form to larger size then lesser size and scroll up all panels are moving downwards and there is empty space at the top. To try to be clearer I fill scrollbox with Tpanels, I expand window to full size scroll down then go back to normal window size, scroll up and nothing is above. The issue only happens if there enough Tpanels to cause scroll to be needed when window is expanded, and I scroll down before unexpanded. The window doesn't need to be fully expanded either just enough to cause the bigger window to need to scroll and scroll down then go back to smaller size and try scrolling up which is just empty.
  3. SillyQuestions

    Issue with dynamic panel creation

    Adjusting ScrollBox1.VertScrollBar.Range seems to fix issue. The other issue related to form resize is fix by just handling the on-size event.
  4. SillyQuestions

    Issue with dynamic panel creation

    Yes, I not really sure what wrong. The width part is minor issue the biggest issue is how resizing the form display things.
×