Solved

More splitter woes

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now