Recent

Author Topic: TDBNavigator Images  (Read 2554 times)

jack

  • Full Member
  • ***
  • Posts: 107
TDBNavigator Images
« on: June 05, 2012, 03:41:39 pm »
Is there an option to change the Arrows in this control?

I would like to replace the Green Drawings with simple text characters.

|<<  <  >  >>|

Thank you for your help.

jack

  • Full Member
  • ***
  • Posts: 107
Re: TDBNavigator Images
« Reply #1 on: August 06, 2012, 03:54:22 am »
After two months I'll Guess its big green arrows going forward.

wp

  • Hero Member
  • *****
  • Posts: 6650
Re: TDBNavigator Images
« Reply #2 on: August 06, 2012, 11:18:41 am »
What about this? Not perfect, but it might give you an idea how to access the hidden DBNavigator buttons. For example, you could replace the glyphs by your own bitmaps in a similar way.

Code: [Select]
type
  TMyDBNavigator = class(TDBNavigator)
  end;

procedure ChangeNavButton(ANavigator:TDBNavigator; ABtn:TDBNavButtontype; ASymbol:string);
begin
  with TMyDBNavigator(ANavigator).Buttons[ABtn] do begin
    Glyph := nil;
    Caption := ASymbol;
    Font.Style := [fsBold];
  end;
end;
{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  ChangeNavButton(DBNavigator1, nbPrior, ' < ');
  ChangeNavButton(DBNavigator1, nbNext,  ' > ');
  ChangeNavButton(DBNavigator1, nbFirst, ' |« ');
  ChangeNavButton(DBNavigator1, nbLast,  ' »| ');
end;
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

jack

  • Full Member
  • ***
  • Posts: 107
Re: TDBNavigator Images
« Reply #3 on: August 07, 2012, 11:59:33 pm »
Thanks for the help.

M.A.R.C.

  • Jr. Member
  • **
  • Posts: 69
Re: TDBNavigator Images
« Reply #4 on: August 30, 2019, 08:23:32 am »
What about this? Not perfect, but it might give you an idea how to access the hidden DBNavigator buttons. For example, you could replace the glyphs by your own bitmaps in a similar way.

Code: [Select]
type
  TMyDBNavigator = class(TDBNavigator)
  end;

procedure ChangeNavButton(ANavigator:TDBNavigator; ABtn:TDBNavButtontype; ASymbol:string);
begin
  with TMyDBNavigator(ANavigator).Buttons[ABtn] do begin
    Glyph := nil;
    Caption := ASymbol;
    Font.Style := [fsBold];
  end;
end;
{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  ChangeNavButton(DBNavigator1, nbPrior, ' < ');
  ChangeNavButton(DBNavigator1, nbNext,  ' > ');
  ChangeNavButton(DBNavigator1, nbFirst, ' |« ');
  ChangeNavButton(DBNavigator1, nbLast,  ' »| ');
end;

Lazarus 2.0.5 r61738
FPC 3.0.4

Error EInvalidClass: Invalid type cast
in TMyDBNavigator(ANavigator).Buttons[ABtn]

wp

  • Hero Member
  • *****
  • Posts: 6650
Re: TDBNavigator Images
« Reply #5 on: August 30, 2019, 09:26:51 am »
No compilation issue for me (Win 10, Laz 3.2/fpc3.0.4, Laz 2.0.4/fpc3.0.4).

Or you can avoid the "hacker's typecast" by this modification:
Code: Pascal  [Select]
  1. procedure ChangeNavButton(ANavigator:TDBNavigator; ABtn:TDBNavButtontype; ASymbol:string);
  2. var
  3.   i: Integer;
  4.   btn: TDBNavButton;
  5. begin
  6.   for i:=0 to ANavigator.ControlCount-1 do
  7.     if (ANavigator.Controls[i] is TDBNavButton) then begin
  8.       btn := TDBNavButton(ANavigator.Controls[i]);
  9.       if btn.Index = ABtn then begin
  10.         btn.Glyph := nil;
  11.         btn.Caption := ASymbol;
  12.         btn.Font.Style := [fsBOld];
  13.         exit;
  14.       end;
  15.     end;
  16. end;
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10