Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Individual hints on TPageControl

Posted on 2004-03-31
8
Medium Priority
?
820 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 600 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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