Solved

Individual hints on TPageControl

Posted on 2004-03-31
8
810 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 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