Solved

Individual hints on TPageControl

Posted on 2004-03-31
8
811 Views
Last Modified: 2010-04-16
Hi, experts!

I need to show individual hints on TPageControl. What I mean is that I need the TabSheet showing the same hint of its page.
How do I do this?
If possible, I would like to create a component descendant of TPageControl with this feature.

Thanks in advance,

Hederglan
0
Comment
Question by:hederglan
  • 5
  • 2
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10723564
??
What I mean is that I need the TabSheet showing
the same hint of its page.

ehem, what??
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10723604
maybe this?

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.PageControl1Change(Sender: TObject);
begin
  pagecontrol1.hint := pagecontrol1.ActivePage.Hint;
end;

end.

btw. the hint of the pagecontrol should be init with the hint of th activepage at designtime, otherwise first hintshow fails.

meikl ;-)
0
 
LVL 1

Author Comment

by:hederglan
ID: 10724225
Meikl,

My point is show the page's hint when the user pass the mouse over the pageControl...even if the page isn't the active page...

Hederglan
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10724502
you mean the tabs?
well then you should derive the tpagecontrol,
or use the onhint-event of tapplication.

i could post tomorrow a derived class,
which could do this hintswapping.

meikl ;-)
0
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.

 
LVL 11

Accepted Solution

by:
shaneholmes earned 150 total points
ID: 10727293
Here is an example:
I have include the unit to the demo I created (main form with a PageControl)

Make sure you set the hint property for each tab and ShowHints = true for PageControl.

Also, you will need to create a MouseMove event for each TabSheet

Shane

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    procedure TabSheet1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure TabSheet2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure TabSheet3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure PageControl1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
    function FindPageforTabIndex( pagecontrol: TPagecontrol; tabindex: Integer ):TTabSheet;
    function HintForTab( pc: TPagecontrol; tabindex: Integer ): String;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


function TForm1.FindPageforTabIndex( pagecontrol: TPagecontrol; tabindex: Integer ):
TTabSheet;
Var
  i: Integer;
Begin
  Assert( Assigned( pagecontrol ));
  Assert( (tabindex >= 0) and (tabindex < pagecontrol.pagecount ));
  Result := nil;
  For i:= 0 To pagecontrol.pagecount-1 Do
    If pagecontrol.pages[i].tabVisible Then Begin
      Dec( tabindex );
      If tabindex < 0 Then Begin
        result := pagecontrol.pages[i];
        break;
      End;
    End;
end;

function TForm1.HintForTab( pc: TPagecontrol; tabindex: Integer ): String;
var
  tabsheet: TTabsheet;
begin
  tabsheet := FindPageforTabIndex( pc, tabindex );
  If assigned( tabsheet ) Then
    result := tabsheet.hint
  else
    result := '';
end;


procedure TForm1.TabSheet1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 pagecontrol1.Hint := '';
end;

procedure TForm1.TabSheet2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 pagecontrol1.Hint := '';
end;

procedure TForm1.TabSheet3MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 pagecontrol1.Hint := '';
end;

procedure TForm1.PageControl1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  tabindex: Integer;
  pc: TPagecontrol;
  newhint: String;
begin
  pc := sender as tpagecontrol;
  tabindex := pc.IndexOfTabAt( X, Y );
  if tabindex >= 0 then begin
    newhint := HintForTab( pc, tabindex );
    if newhint <> pc.Hint then begin
      pc.Hint := newhint;
      application.CancelHint;
    end;
  end
  else
    pc.Hint := '';
end;

end.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10729915
well, my version :-))

unit HintPageControl;

interface

uses
  SysUtils, Classes, Controls, ComCtrls, commctrl, messages;

type
  THintPageControl = class(TPageControl)
  private
    fHintDefault : string;
  protected
    procedure WMMouseMove(var Message : TWMMouseMove); message WM_MouseMove;
  public
    { Public declarations }
  published
    property HintDefault : string read fHintDefault write fHintDefault;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [THintPageControl]);
end;

procedure THintPageControl.WMMouseMove(var Message : TWMMouseMove);
var
  tabInfo : TC_HITTESTINFO;
  tabidx  : Integer;
begin
  tabInfo.pt := point(message.XPos,message.YPos);
  tabidx := perform(TCM_HITTEST,0,integer(@tabInfo));
  if tabidx = -1 then
    hint := hintdefault
  else
    hint := pages[tabidx].Hint;
  inherited;
end;

end.

meikl ;-)
0
 
LVL 1

Author Comment

by:hederglan
ID: 10741110
I will accept Shane's answer because it allows the hint to change if the mouse passes over more than one page...

Meikl, thank you for your answers.

Regards,

Hederglan
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10741756
>...because it allows the hint to change if
>the mouse passes over more than one page...

guessing you didn't try ma derived component :-))
but well, its ok

meikl ;-)
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
PDF library for Delphi 2 107
find a node in VST 2 64
can't find the executable in Simulator 1 80
IdTCPClient and IdTCPServer exchanging data on desktops and not Android 11 96
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

24 Experts available now in Live!

Get 1:1 Help Now