Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

More splitter woes

Posted on 2004-08-12
5
Medium Priority
?
197 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 1200 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 800 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

971 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