StringGrid

ataeallah Messages postés 37 Date d'inscription mercredi 2 janvier 2002 Statut Membre Dernière intervention 17 juin 2010 - 30 mai 2003 à 12:11
cs_Delphiprog Messages postés 4297 Date d'inscription samedi 19 janvier 2002 Statut Membre Dernière intervention 9 janvier 2013 - 30 mai 2003 à 15:59
Bonjour,
Comment je peux écrire des chiffres à droits dans une cellule à l'aide de OnDrawCell ?
Merci
ABDA
@+

1 réponse

cs_Delphiprog Messages postés 4297 Date d'inscription samedi 19 janvier 2002 Statut Membre Dernière intervention 9 janvier 2013 32
30 mai 2003 à 15:59
Voici la réponse :
procedure TForm1.FormCreate(Sender: TObject);
begin
//juste pour indiquer comment paramètrer le TStringGrid  
with StringGrid1 do
  begin
    Options := Options + [goDrawFocusSelected];
    DefaultDrawing := True;
  end;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  sWidth : integer;
begin
   with StringGrid1 do
    //ne pas cadrer les titres
    if not (gdFixed in state)then
    begin
      Canvas.FillRect(Rect);
      sWidth := Canvas.TextWidth(Cells[ACol, ARow]) + 2;
      Canvas.TextOut(Rect.Right - sWidth, Rect.Top + 2, Cells[ACol, ARow]);
    end;
    StringGrid1.DefaultDrawing := True;
end;

En résumé, il suffit de déterminer la position de début d'écriture de la chaîne de caractères.
May Delphi be with you
0
Rejoignez-nous