• Viernes 26 de Abril de 2024, 21:25

Autor Tema:  Color De Celdas En Stringgrid  (Leído 5511 veces)

jumanor

  • Nuevo Miembro
  • *
  • Mensajes: 17
    • Ver Perfil
    • http://jumanor.webcindario.com
Color De Celdas En Stringgrid
« en: Domingo 7 de Diciembre de 2003, 03:54 »
0
necesito cambiar el color de fondo de una determinada celda en un StringGrid

gracias por su apoyo

_Viktor

  • Miembro MUY activo
  • ***
  • Mensajes: 271
    • Ver Perfil
    • http://AyudaCBuilder.foros.st
Re: Color De Celdas En Stringgrid
« Respuesta #1 en: Martes 9 de Diciembre de 2003, 00:55 »
0
Creo que esto te servira, lo que hace es pintar las FixedRows y FixedColumms en Negro y la celda seleccionada en Amarillo, va en el evento OnDrawCell del StringGrid.


Código: Text
  1. void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
  2.       int ARow, TRect &Rect, TGridDrawState State)
  3. {
  4. TStringGrid* Grilla = static_cast<TStringGrid*>(Sender);
  5. TCanvas *canvas = dynamic_cast<TStringGrid*>(Sender)->Canvas;
  6. TRect r(Rect);
  7. canvas->Font=Grilla->Font;
  8.  
  9. //Aqui pinta las celdas Fixed
  10. if(ACol==0 || ARow==0)
  11. {
  12.   canvas->Brush->Color = clBlack;
  13. }
  14.  
  15.  
  16. //Aqui las Seleccionadas.
  17. if(State.Contains(gdSelected))
  18. {
  19.       canvas->Font->Color = clWindow;
  20.       canvas->Brush->Color = clYellow;
  21. }
  22. canvas->FillRect(r);
  23. DrawText(canvas->Handle, StringGrid1->Cells[ARow][ACol].c_str(), StringGrid1->Cells[ARow][ACol].Length(), &r,DT_LEFT);
  24. }
  25.  

O si lo que quieres es cambiar el color de una celda de acuerdo a su contenido puedes hacer esto:

Código: Text
  1. //---------------------------------------------------------------------------
  2. __fastcall TForm1::TForm1(TComponent* Owner)
  3.         : TForm(Owner)
  4. {
  5. StringGrid1->Cells[2][1] = "rojo";
  6. StringGrid1->Cells[3][1] = "verde";
  7. StringGrid1->Cells[2][2] = "celeste";
  8. StringGrid1->Cells[2][3] = "Azul";
  9. }
  10. //---------------------------------------------------------------------------
  11.  
  12. void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
  13.       int ARow, TRect &Rect, TGridDrawState State)
  14. {
  15. if ((ACol>0) && (ARow>0))
  16. {
  17.   if (StringGrid1->Cells[ACol][ARow] == "rojo")
  18.     StringGrid1->Canvas->Brush->Color = clRed;
  19.   else if (StringGrid1->Cells[ACol][ARow] == "verde")
  20.     StringGrid1->Canvas->Brush->Color = clGreen;
  21.   else if (StringGrid1->Cells[ACol][ARow] == "celeste")
  22.     StringGrid1->Canvas->Brush->Color = clAqua;
  23.   else if (StringGrid1->Cells[ACol][ARow] == "Azul")
  24.     StringGrid1->Canvas->Brush->Color = clBlue;
  25.   else
  26.     StringGrid1->Canvas->Brush->Color = clBlack;
  27.  
  28.  StringGrid1->Canvas->FillRect(Rect);
  29.  StringGrid1->Canvas->TextOut(Rect.Left,Rect.Top,StringGrid1->Cells[ACol][ARow]);  }
  30. }
  31. //---------------------------------------------------------------------------
  32.  


Haber si era lo que necesitabas.
Saludos!!!
_Viktor _Yañez_
"Ser inteligente no es ser mas, solo equivocarse menos y no usar visual basic"

http]