Fórum Mudar a ordem dos botões do DBNavigator?! #317551
28/03/2006
0
Pode ser qualquer coisa, até um novo componente a partir de TDBNavigator!
Pedron
Curtir tópico
+ 0Posts
28/03/2006
Paullsoftware
coloquei dois DbNavigator, se vc conseguir posta ai que ainda quero...
Gostei + 0
28/03/2006
Adriano Santos
type TDBNewNavigator = class( TDbNavigator );
Assim nós conseguimos acessar os buttons do DBNavigator.
procedure TForm1.Button1Click(Sender: TObject); var B: TNavigateBtn; begin for B := Low(TNavigateBtn) to High(TNavigateBtn) do begin with TDBNewNavigator(DBNavigator1).Buttons[B] do begin Case Index of nbFirst : Left := 72; nbPrior : Left := 216; nbNext : Left := 48; nbLast : Left := 0; nbInsert : Left := 192; nbDelete : Left := 96; nbEdit : Left := 144; nbPost : Left := 120; nbCancel : Left := 168; nbRefresh: Left := 24; end; end; end; end;
Dá pra alterar tudo dos botões.
Aqui eu fiz uma brincadeira, alterei todas as posições. Elas começam em zero dentro do DBNabigator, ou seja, o First fica em left = 0, prior = 24 e etc.
Gostei + 0
28/03/2006
Martins
boa sorte!
Gostei + 0
28/03/2006
Pedron
E como eu poderia mudar a ordem caso fosse criar um novo componente? só colocar esse código no create do componente?
Gostei + 0
28/03/2006
Pedron
experimentem por um outro botão com o código:
DBNavigator1.Align:=alClient;
e vejam o resultado
Gostei + 0
28/03/2006
Rjun
Deve ter algum evento do tipo OnResize. Coloque esse código nesse evento também.
Gostei + 0
29/03/2006
Adriano Santos
[b:1ae3d7bc1a]pedron[/b:1ae3d7bc1a] o [b:1ae3d7bc1a]Rjun[/b:1ae3d7bc1a] está certo. Ser olharmos a unit DBCtrls, onde se encontra declarada a classe DBNavigator, veremos que existe realmente um procedimento para redimencionamento automático do DBNavigator, o SetSize;
procedure TDBNavigator.SetSize(var W: Integer; var H: Integer); var Count: Integer; I: TNavigateBtn; Space, Temp, Remain: Integer; X: Integer; begin if (csLoading in ComponentState) then Exit; if Buttons[nbFirst] = nil then Exit; CalcMinSize(W, H); Count := 0; for I := Low(Buttons) to High(Buttons) do if Buttons[I].Visible then Inc(Count); if Count = 0 then Inc(Count); ButtonWidth := W div Count; Temp := Count * ButtonWidth; if Align = alNone then W := Temp; X := 0; Remain := W - Temp; Temp := Count div 2; for I := Low(Buttons) to High(Buttons) do begin if Buttons[I].Visible then begin Space := 0; if Remain <> 0 then begin Dec(Temp, Remain); if Temp < 0 then begin Inc(Temp, Count); Space := 1; end; end; Buttons[I].SetBounds(X, 0, ButtonWidth + Space, Height); Inc(X, ButtonWidth + Space); end else Buttons[I].SetBounds (Width + 1, 0, ButtonWidth, Height); end; end;
E mais um outro que detecta a alteração de tamanho do DBNavigator, WMSize;
procedure TDBNavigator.WMSize(var Message: TWMSize); var W, H: Integer; begin inherited; W := Width; H := Height; SetSize(W, H); end;
Como disse o [b:1ae3d7bc1a]Rjun[/b:1ae3d7bc1a] existe o evento onResize onde vc pode implementar seu algoritimo. Há ainda a opção de modificar todo o DBNav como mostrado no exemplo abaixo:
[list:1ae3d7bc1a]
[*:1ae3d7bc1a] Inclua um TImageList com 10 imagens
[*:1ae3d7bc1a] Inclua uma TTable ligada no DBDEMOS e selecione uma tabela para testar
[*:1ae3d7bc1a] Insira um DBGrid pra ver o resultado
[/list:u:1ae3d7bc1a]
No OnCreate do Form inclua o algoritimo:
procedure TForm1.FormCreate(Sender: TObject);
var
B: TNavigateBtn;
procedure Reajusta(ABotao : TNavigateBtn);
begin
with TDBNewNavigator(DBNavigator1).Buttons[ABotao] do
begin
Width := 70;
Height := 70;
Layout := blGlyphTop;
Case Index of
nbFirst : Top := 000;
nbLast : Top := 000;
nbInsert : Top := 000;
nbEdit : Top := 000;
nbPost : Top := 000;
nbPrior : Top := 070;
nbNext : Top := 070;
nbCancel : Top := 070;
nbDelete : Top := 070;
nbRefresh : Top := 070;
end;
end;
end;
procedure AtualizaBitmap(AIndex: Integer; ABotao : TNavigateBtn);
var
Bmp : TBitmap;
begin
Bmp := TBitMap.Create;
with Bmp do
begin
{configuramos que a cor transparente será branco}
TransparentColor := clWhite;
Transparent := True;
TransparentMode := tmAuto
end;
ImageList1.GetBitmap(AIndex, Bmp);
{Detectamos se a altura do título é suficiente para por a imagem}
with TDBNewNavigator(DBNavigator1).Buttons[ABotao] do
Glyph := Bmp;
FreeAndNil(Bmp);
end;
begin
Table1.Active := True;
TDBNewNavigator(DBNavigator1).ClientHeight := 140;
TDBNewNavigator(DBNavigator1).ClientWidth := 350;
TDBNewNavigator(DBNavigator1).Left := (Form1.Width div 2) - (350 div 2);
for B := Low(TNavigateBtn) to High(TNavigateBtn) do
Reajusta(B);
for B := Low(TNavigateBtn) to High(TNavigateBtn) do
begin
with TDBNewNavigator(DBNavigator1).Buttons[B] do
begin
Layout := blGlyphTop;
Font.Color := clNavy;
Font.Style := [fsBold];
Case Index of
nbFirst : begin Left := 000; Caption := ´Início´; Hint := ´Vai para o INÍCIO da tabela´; AtualizaBitmap(00, B); end;
nbLast : begin Left := 070; Caption := ´Fim´; Hint := ´Vai para o FIM da tabela´; AtualizaBitmap(02, B); end;
nbInsert : begin Left := 140; Caption := ´Novo´; Hint := ´Inclui um NOVO registro´; AtualizaBitmap(08, B); end;
nbEdit : begin Left := 210; Caption := ´Alterar´; Hint := ´ALTERA o registro atual´; AtualizaBitmap(10, B); end;
nbPost : begin Left := 280; Caption := ´Gravar´; Hint := ´GRAVA o registro atual´; AtualizaBitmap(16, B); end;
nbPrior : begin Left := 000; Caption := ´Anteior´; Hint := ´Vai para o regitro ANTERIOR´; AtualizaBitmap(04, B); end;
nbNext : begin Left := 070; Caption := ´Próximo´; Hint := ´Vai para o PRÓXIMO registro´; AtualizaBitmap(06, B); end;
nbCancel : begin Left := 140; Caption := ´Cancelar´; Hint := ´CANCELA a alteração atual´; AtualizaBitmap(14, B); end;
nbDelete : begin Left := 210; Caption := ´Apagar´; Hint := ´APAGA o registro atual´; AtualizaBitmap(12, B); end;
nbRefresh : begin Left := 280; Caption := ´Atualizar´;Hint := ´ATUALIZA a tabela´; AtualizaBitmap(18, B); end;
end;
end;
end;
end;
No OnResize do DBNavigator link o evento ao onCreate do Form;
[list:1ae3d7bc1a]
[*:1ae3d7bc1a]Obs 1 - A propriedade Align funciona assim mesmo, redimenciona automaticamente. Você pode criar um novo componente herdado do DBNav e sobrescrever todos os seus métodos, eventos e propriedades.
[*:1ae3d7bc1a]Obs 2 - O algoritimo do meu segundo exemplo está um pouco extenso, mas se notar estou mudando totalmente a posição dos botões, colocando novas figuras, mudando hints e etc.
[/list:u:1ae3d7bc1a]
Veja uma foto da tela funcionando:
[img:1ae3d7bc1a]http://www.doiscliques.com/pub/dbnav.jpg[/img:1ae3d7bc1a]
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)