Solved

Individual hints on TPageControl

Posted on 2004-03-31
8
817 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 70
Intraweb download file link ? 1 184
Typecasting TBytes to Integer in Delphi XE8 2 68
Remove all child-forms from a parent-panel 16 14
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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