Solved

More splitter woes

Posted on 2004-08-12
5
193 Views
Last Modified: 2010-04-05
Hi,

my form looks like this:
------------------------------
Panel1   Splitter1   Panel2
alClient  alRight     alRight
------------------------------
If I change the parent property of the form (Nil -> TabSheet) my controls get messed up. If the size of the TabSheet is different than the size of my form I expect my controls to resize but they don't. Actually I use Form1.Width := Form1.Width - 1 to get it done but that's goofy. Any hint apprechiated.

Thanks in advance.
0
Comment
Question by:__alex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Author Comment

by:__alex
ID: 11790776
Oops, forgot to mention:
I set the Splitter1.Visible property in the OnFormHide and OnFormShow event <--- http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21092429.html
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 300 total points
ID: 11790883
//........ Project:
program Q_21092433;

uses
  Forms,
  Unit1_Q_21092433 in 'Unit1_Q_21092433.pas' {Form1},
  Unit2_Q_21092433 in 'Unit2_Q_21092433.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.
//........ Unit1:
unit Unit1_Q_21092433;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, Buttons, ToolWin;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
  private   { Private declarations }
  public    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  Unit2_Q_21092433;

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  Form2.Show;
end;

end.
//........ Form1:
object Form1: TForm1
  Left = 200
  Top = 114
  Width = 696
  Height = 480
  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 PageControl1: TPageControl
    Left = 0
    Top = 29
    Width = 688
    Height = 417
    ActivePage = TabSheet1
    Align = alClient
    TabOrder = 0
    object TabSheet1: TTabSheet
      Caption = 'TabSheet1'
    end
    object TabSheet2: TTabSheet
      Caption = 'TabSheet2'
      ImageIndex = 1
    end
  end
  object ToolBar1: TToolBar
    Left = 0
    Top = 0
    Width = 688
    Height = 29
    Caption = 'ToolBar1'
    TabOrder = 1
    object SpeedButton1: TSpeedButton
      Left = 0
      Top = 2
      Width = 81
      Height = 22
      Caption = 'Form2'
      OnClick = SpeedButton1Click
    end
  end
end
//........ Unit2:
 unit Unit2_Q_21092433;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Buttons, ToolWin, ComCtrls;

type
  TForm2 = class(TForm)
    Panel1: TPanel;
    Splitter1: TSplitter;
    Panel2: TPanel;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private   { Private declarations }
  public    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

uses
  Unit1_Q_21092433;

procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
  Parent := Form1.TabSheet1;
  Splitter1.Left := Panel2.Left - Splitter1.Width - 2;
end;

procedure TForm2.SpeedButton2Click(Sender: TObject);
begin
  Parent := nil;
  Splitter1.Left := Panel2.Left - Splitter1.Width - 2;
end;

end.
//........ Form2:
object Form2: TForm2
  Left = 200
  Top = 114
  Width = 514
  Height = 392
  Caption = 'Form2'
  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 Splitter1: TSplitter
    Left = 253
    Top = 29
    Height = 329
    Align = alRight
  end
  object Panel1: TPanel
    Left = 0
    Top = 29
    Width = 253
    Height = 329
    Align = alClient
    Caption = 'Panel1'
    TabOrder = 0
  end
  object Panel2: TPanel
    Left = 256
    Top = 29
    Width = 250
    Height = 329
    Align = alRight
    Caption = 'Panel2'
    TabOrder = 1
  end
  object ToolBar1: TToolBar
    Left = 0
    Top = 0
    Width = 506
    Height = 29
    Caption = 'ToolBar1'
    TabOrder = 2
    object SpeedButton1: TSpeedButton
      Left = 0
      Top = 2
      Width = 128
      Height = 22
      Caption = 'Parent -> TabSheet'
      OnClick = SpeedButton1Click
    end
    object SpeedButton2: TSpeedButton
      Left = 128
      Top = 2
      Width = 128
      Height = 22
      Caption = 'Parent -> nil'
      OnClick = SpeedButton2Click
    end
  end
end

emil
0
 
LVL 2

Author Comment

by:__alex
ID: 11791925
I guess that's what I do :-(
I will come back to you on Monday. Have a nice weekend!
0
 
LVL 2

Assisted Solution

by:beermequik
beermequik earned 200 total points
ID: 11796703
Set Form2's  Alignment to alClient, either in the Object Inspector, or programatically,
just before you set to parent property to the TabSheet.

You can also set it back to alNone when you set the parent to nil.

But if this was done after setting it to client, it will show up the upper left of the screen, and sized the same as the tabsheet

To remedy this, you could have variables intOldTop, intOldLeft, intOldHeight, and intOldWidth and set their values to the current top, left, height and width just before setting client.

//Form2's public
intOldTop, intOldLeft, intOldWidth, intOldHeight : integer;

//Form2's OnCreate event
  // initialize the "old" sizes
  intOldLeft := Left;
  intOldTop := Top;
  intOldWidth := Width;
  intOldHeight := Height;



procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
  intOldLeft := Left;
  intOldTop := Top;
  intOldWidth := Width;
  intOldHeight := Height;
  Self.Align := alClient;
  Parent := Form1.TabSheet1;
end;

procedure TForm2.SpeedButton2Click(Sender: TObject);
begin
 
  Self.Align := alNone;
  Left := intOldLeft;
  Top := intOldTop;
  Width := intOldWidth;
  Height := intOldHeight;
  Parent := nil;
end;

Hope that helps
0
 
LVL 2

Author Comment

by:__alex
ID: 11807479
Back in the office again...

I guess I have to apologize again: I forgot to mention I already do align the form:

procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
  Parent := Form1.TabSheet1;
  Splitter1.Left := Panel2.Left - Splitter1.Width - 2;
  Form2.Align := alClient;
end;

procedure TForm2.SpeedButton2Click(Sender: TObject);
begin
  Parent := nil;
  Splitter1.Left := Panel2.Left - Splitter1.Width - 2;
  Form2.Align := alNone;
end;

If Panel2.Width is greater than the width of the tabsheet and I make the panel appear in the tabsheet the splitter is sort of "under" Panel2. Furthermore this does not happen with D7 but with D5. I guess I stay with my "Form1.Width := Form1.Width - 1" workaround and close this question. Thanks for your effort!

Alex
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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