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
Solved

More splitter woes

Posted on 2004-08-12
5
192 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run video youtube webbrowse 10 65
Downloading email attachments 2 79
creating threads in delphi 1 131
Dynamically Created Query 3 62
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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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