Link to home
Start Free TrialLog in
Avatar of ysimon
ysimon

asked on

How to set a TabSheet disabled

I am using a PageControl, under which there are several TabSheets.
I need to disable one of them. I try to set the TabSheet property Enable=False,
it only works for all components on that page, the page is still can be opened.
I want the page cannot be opened, how can I do?

ysimon
ASKER CERTIFIED SOLUTION
Avatar of DeNavigator
DeNavigator

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DeNavigator
DeNavigator

However it is not following windows standards. If a tab is visible a user can select it so it would be better if you made the tab invisible if you don't want the user to select it.
SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes that is coorect.  I have just written this quick example.  Here is the form code


object Form1: TForm1
  Left = 192
  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 = 96
    Top = 32
    Width = 457
    Height = 329
    ActivePage = TabSheet3
    HotTrack = True
    TabIndex = 2
    TabOrder = 0
    object TabSheet1: TTabSheet
      Caption = 'Sheet1'
      object Label1: TLabel
        Left = 168
        Top = 88
        Width = 97
        Height = 24
        Caption = 'Sheet 1'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clNavy
        Font.Height = -19
        Font.Name = 'MS Sans Serif'
        Font.Style = []
        ParentFont = False
      end
    end
    object TabSheet2: TTabSheet
      Caption = 'Sheet2'
      ImageIndex = 1
      object Label4: TLabel
        Left = 168
        Top = 104
        Width = 64
        Height = 24
        Caption = 'Sheet 2'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clAqua
        Font.Height = -19
        Font.Name = 'MS Sans Serif'
        Font.Style = []
        ParentFont = False
      end
    end
    object TabSheet3: TTabSheet
      Caption = 'Sheet3'
      ImageIndex = 2
      object Label3: TLabel
        Left = 168
        Top = 128
        Width = 73
        Height = 24
        Caption = 'Sheet 3'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clTeal
        Font.Height = -19
        Font.Name = 'MS Sans Serif'
        Font.Style = []
        ParentFont = False
      end
    end
    object TabSheet4: TTabSheet
      Caption = 'Sheet4'
      ImageIndex = 3
      object Label2: TLabel
        Left = 168
        Top = 152
        Width = 64
        Height = 24
        Caption = 'Sheet 4'
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clRed
        Font.Height = -19
        Font.Name = 'MS Sans Serif'
        Font.Style = []
        ParentFont = False
      end
    end
  end
  object Button1: TButton
    Left = 120
    Top = 336
    Width = 75
    Height = 17
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
end


// and the unit


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    Button1: TButton;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);
begin
tabsheet3.tabvisible := false;
end;

end.


// if you want the tab to re-appear just add another button and  use
tabsheet3.tabvisible := true;
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nope !  That would cause an error as in my form the name of the component is 'tabsheet3'
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Will you be replying to us soon :)
Hello ?  :)
I think you want your TabSheets remain visible, but only one is inactive or disabled, so nothing happens if the user clicks on its tab. I have tried this, and it works for me:

( MyPageControl = name of the TPageControl )

Using the Object Inspector, mark
MyPageControl.AccessibleDisabledPages as FALSE

At runtime, making any TabSheet.Enabled := FALSE will make it unusable yet still visible, until you write TabSheet.Enabled := TRUE