Alternative owner of a form

I fond some code by Marco Cantu that puts a form inside a TTabsheat so mutiple forms can be shown inside a TPageControl. Very nice, much better and more stable than frames, and FormCteateEvents can be used.  Now i need the same, but without any visible tabs, but i cant find any way to have a TTabsheat inside a TPageControl without the tab visible.

So my question is, can the tab part be invisible or is there some other way to do this? I tried with TGroupBox, but it cant be the "owner" of a form. I add the code that puts a form into a ttabsheet.
NewTabSheet:=TTabSheet.Create(MyTpageControl);

    with  NewTabSheet do begin
      PageControl:=MyTpageControl;
    end;

    Form:=TMyForm.Create(Application);

    with Form do begin
 
       BorderStyle:=bsNone;
       Align:=alClient;
       Parent:=NewTabSheet;
       Visible:=True;

    end;

    MyTpageControl.ActivePage:=NewTabSheet;
    NewTabSheet.Caption:='Hi';

Open in new window

Paer ToernellAsked:
Who is Participating?
 
jimyXCommented:
Ya I got it. What I meant is to hide all the tabs then show the particular tab that you want by clicking a button for instance, if the PageControl has two tabs then the code goes as follows:
procedure TForm1.FormCreate(Sender: TObject);
begin
  PageControl1.Pages[0].TabVisible := False;
  PageControl1.Pages[1].TabVisible := False;
  PageControl1.Pages[0].Visible := True;
  PageControl1.TabIndex:= 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // to show tab 1
  PageControl1.Pages[0].Visible := True;
  PageControl1.Pages[1].Visible := False;
  PageControl1.TabIndex:= 0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  // to show tab 2
  PageControl1.Pages[0].Visible := False;
  PageControl1.Pages[1].Visible := True;
  PageControl1.TabIndex:= 1;
end;

Open in new window

0
 
Ephraim WangoyaCommented:

There are two ways you can do it

1. Get DevExpress TcxPageControl component which has HideTabs property
2. Make your own HideTabs property and override the WindowProc method and redraw the tabs your self


unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, CommCtrl;

type
  TPageControl = class(ComCtrls.TPageControl)
  private
    FHideTabs: Boolean;
    procedure SetHideTabs(const Value: Boolean);
  protected
    procedure WndProc(var Message: TMessage); override;
  public
    property HideTabs: Boolean read FHideTabs write SetHideTabs;
  end;

  TForm3 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

{ TPageControl }

procedure TPageControl.SetHideTabs(const Value: Boolean);
begin
  if FHideTabs <> Value then
  begin
	  FHideTabs := Value;
    if not (csLoading in ComponentState) then
    	Invalidate; //let it redraw
  end;
end;

procedure TPageControl.WndProc(var Message: TMessage);
var
	R: PRect;
begin
  inherited WndProc(Message);
  if Message.Msg =TCM_ADJUSTRECT then
  begin
    inherited WndProc(Message);
    //you need to show the tabs when designing
    if FHideTabs and (not (csDesigning	in ComponentState)) then
    begin
      R := PRect(Message.LParam);
      if R <> nil then
      begin
        R^.Left := 0;
        if TabPosition = tpTop then
          R^.Top := -2
        else
          R^.Top := 0;
        R^.Right := ClientWidth;
        R^.Bottom := ClientHeight;
      end;
    end;
  end;
end;

procedure TForm3.FormCreate(Sender: TObject);
begin
  PageControl1.HideTabs := True;
  PageControl1.Invalidate;
  Application.ProcessMessages;
end;

end.

Open in new window

0
 
jimyXCommented:
Each TabSheet in the TPageControl has property "Tabvisible" just set it to False.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ephraim WangoyaCommented:

@jimmyX

TabSheet1.TabVisible := False;
The TabVisible property hides the whole Tab so the user will not see that particular tab, but all the other Tab headings are still visible, you can still navigate to each Tab that is visible
The idea is to hide the tab headings, sort of a wizard where you only have a next and previous button
0
 
Ephraim WangoyaCommented:

@jimyX
Thats a lot of data to keep track of, but it can work
0
 
jimyXCommented:
@ ewangoya,
I am just showing an example, it can be done in a very neat way.
0
 
Paer ToernellAuthor Commented:
Nice, its only one line of code i need. TabVisible:=False;
0
 
jimyXCommented:
If you want to hide all the tabs, update the OnFormCreate to be as follows:
procedure TForm1.FormCreate(Sender: TObject);
var
  i:integer;
begin
  for i:= 0 to PageControl1.PageCount-1 do
    begin
      PageControl1.Pages[i].TabVisible := False;
    end;
  
  PageControl1.Pages[x].Visible := True;// x will be the first showing form, if any. the first tab is 0
end;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.