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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.