Comment donner une couleur seulement à une case du StringGrid - Delphi/Pascal - Programmation
Marsh Posté le 28-04-2006 à 06:58:37
Ou par exemple un bazar du genre : 
 
procedure TCalendrier.StGridPersoDrawCell(Sender: TObject; ACol, 
  ARow: Integer; Rect: TRect; State: TGridDrawState); 
  var s:string; 
begin 
    with StGridPerso do begin 
         if ((ARow mod 2)<>1) then 
            begin 
                canvas.brush.color:=CouleurImpair; 
                canvas.FillRect(rect); 
            end 
         else 
            begin 
                canvas.brush.color:=Couleurpair; 
                canvas.FillRect(rect); 
            end; 
 
         if (gdFixed in state)  then begin 
           if ( ARow=0) and (ACol in [0..1]) then 
                begin 
                    canvas.brush.color:=CouleurFix; 
                    canvas.FillRect(rect); 
                    canvas.font.style:=[fsbold]; 
                    s:=cells[Acol,0]; 
                    DrawText(Canvas.Handle,PChar(s),StrLen(PChar(s)),Rect,DT_CENTER); 
                end 
            else if ( ARow=0) and (ACol =2) then 
                begin 
                    canvas.brush.color:=CouleurFixIntitule; 
                    canvas.FillRect(rect); 
                    canvas.font.style:=[fsbold]; 
                    s:=cells[Acol,0]; 
                    DrawText(Canvas.Handle,PChar(s),StrLen(PChar(s)),Rect,DT_CENTER); 
                end; 
         end; 
 
         if (ACol in [0..1]) and (ARow>0) then 
                begin 
                    s:=uppercase(cells[ACol,ARow]); 
                    DrawText(Canvas.Handle,PChar(s),StrLen(PChar(s)),Rect,DT_CENTER); 
                end; 
 
         if (ACol =2) and (ARow>0) then 
                begin 
                    canvas.font.color:=clblack; 
                    canvas.FillRect(rect); 
                    canvas.textout(rect.left,rect.top,cells[ACol,ARow]); 
                end; 
 
        if (gdSelected in state) and (Arow >0)  then 
            begin 
                canvas.brush.color:=CouleurSel; 
                canvas.FillRect(rect); 
                canvas.font.color:=clmaroon; 
                canvas.textout(rect.left,rect.top,cells[ACol,ARow]); 
            end; 
 
         if (gdSelected in state) and (Arow >0) and (Acol in [0..1])  then 
         begin 
            canvas.brush.color:=CouleurSel; 
            canvas.FillRect(rect); 
            canvas.font.color:=clmaroon; 
            canvas.font.style:=[fsbold]; 
            s:=cells[Acol,ARow]; 
            DrawText(Canvas.Handle,PChar(s),StrLen(PChar(s)),Rect,DT_CENTER); 
         end; 
end; 
end;
Marsh Posté le 13-04-2006 à 09:49:04
Salut.
Actuellement mon problème est que je voudrais donner une couleur uniquement à une case en particulier dans un StringGrid. Je suis prêt à prendre aussi la coloration totale du ligne complète, mais je ne veux pas colorer tout le StrinGrid. Si quelqu'un à la solution je suis prenneur.
Merci.