Solved

Disable pages in TPagecontrol

Posted on 2001-06-05
4
510 Views
Last Modified: 2011-09-20
Hi,
How to disable the  pages in TpageControl,i.e., when the pages are disabled (tabsheet.enabled = False), the tab text should be grayed out and the tabs (disabled pages) cannot be clicked.  

Thanks.
0
Comment
Question by:llkhor
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6155475
You could set TabVisible to false instead...
0
 

Author Comment

by:llkhor
ID: 6158273
Epsylon : I want the disabled pages (Tabs) to be visible, if i set Tabvisible to False, this will hide the pages completely.  

Thanks.
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6158789
hi,
you could use a component like this (you may want to modify the text colors a bit but it disables the pages from being clicked)


unit PBPageControl;

interface

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

type
  TPBPageControl = class(TPageControl)
  private
    { Private declarations }
    Procedure WMLButtonDown( Var msg: TWMLButtonDown ); message
WM_LBUTTONDOWN;
    Procedure CMDialogKey( Var msg: TWMKey ); message CM_DIALOGKEY;
    procedure SetOwnerdraw(const Value: Boolean);
    function GetOwnerdraw: Boolean;
  protected
    { Protected declarations }
    procedure DrawTab(TabIndex: Integer; const Rect: TRect; Active: Boolean);
override;
  public
    { Public declarations }
    Constructor Create( aOwner: TCOmponent ); override;
  published
    { Published declarations }
    property Ownerdraw: Boolean read GetOwnerdraw write SetOwnerdraw default
True;
  end;

procedure Register;

implementation

Uses CommCtrl;

procedure Register;
begin
  RegisterComponents('PBGoodies', [TPBPageControl]);
end;

{ TPBPageControl }

procedure TPBPageControl.CMDialogKey(var msg: TWMKEY);
var
  thistab, tab: TTabSheet;
  forward: Boolean;
begin
  If (msg.CharCode = Ord(#9)) and (GetKeyState( VK_CONTROL ) < 0) Then
  Begin
    thistab := ActivePage;
    forward := GetKeyState( VK_SHIFT ) >= 0;
    tab := thistab;
    Repeat
      tab := FindNextPage( tab, forward, true );
    Until tab.Enabled or (tab = thistab);
    If tab <> thistab Then Begin
      If CanChange Then Begin
        ActivePage := tab;
        Change;
      End;
      Exit;
    End;
  End;
  inherited;
end;

constructor TPBPageControl.Create(aOwner: TCOmponent);
begin
  inherited;
  OwnerDraw := True;
end;

procedure TPBPageControl.DrawTab(TabIndex: Integer; const Rect: TRect;
  Active: Boolean);
var
  imageindex: Integer;
  r: TRect;
  S: String;
begin
  If not Pages[TabIndex].Enabled Then
    Canvas.Font.Color := clInactiveCaptionText;
  If Active Then
    Canvas.Font.Style := [fsBold];  
  If Assigned( OnDrawTab ) Then
    inherited
  Else Begin
    r:= Rect;
    Canvas.Fillrect( r );
    imageindex := GetImageIndex( tabindex );
    If (imageindex >=0) and Assigned( Images ) Then Begin
      SaveDC( canvas.handle );
      images.Draw( Canvas, Rect.Left+4, Rect.Top+2,
                   imageindex,
                   Pages[TabIndex].enabled );
      // images.draw fouls the canvas colors if it draws
      // the image disabled, thus the SaveDC/RestoreDC
      RestoreDC( canvas.handle, -1 );            
      R.Left := R.Left + images.Width + 4;
    End;
    S:= Pages[ TabIndex ].Caption;
    InflateRect( r, -2, -2 );
    DrawText( Canvas.handle,
              PChar(S),
              Length(S),
              r,
              DT_SINGLELINE or DT_LEFT or DT_TOP );
  End;
end;

function TPBPageControl.GetOwnerdraw: Boolean;
begin
  result := inherited OwnerDraw;
end;

procedure TPBPageControl.SetOwnerdraw(const Value: Boolean);
begin
  inherited OwnerDraw := true;
end;

procedure TPBPageControl.WMLButtonDown(var msg: TWMLButtonDown);
var
  hi: TTCHitTestInfo;
  tabindex: Integer;
begin
  If csDesigning In ComponentState Then Begin
    inherited;
    Exit;
  End;
  hi.pt.x := msg.XPos;
  hi.pt.y := msg.YPos;
  hi.flags := 0;
  tabindex := Perform( TCM_HITTEST, 0, longint(@hi));
  If (tabindex >= 0) and ((hi.flags and TCHT_ONITEM) <> 0)
  Then
    If not Pages[ tabindex ].Enabled Then Begin
      msg.result := 0;
      Exit;
    End;
  inherited;
end;

end.
0
 

Author Comment

by:llkhor
ID: 6175929
Thanks ....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 55
Error E2158 compiling with Delphi XE10 Seattle 2 86
Performance of SQL statement 37 97
Delphi...Split view - idea? 1 41
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

21 Experts available now in Live!

Get 1:1 Help Now