Solved

More splitter woes

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

13 Experts available now in Live!

Get 1:1 Help Now