Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   Duda con StringGrid (https://www.clubdelphi.com/foros/showthread.php?t=64717)

BC++ 15-04-2009 23:05:27

Duda con StringGrid
 
Hola Amigos del foro:

En este caso, mi pregunta es si existe alguna manera de centrar los datos en un StrigGrid en Builder C++.

for( int i=0;i<10;i++){
StringGrid1->Cell[0][i]=i; /*//esto es lo comun, pero esta siempre del lado izq y me gustaria q este centrado*/

}

Desde ya, muchas gracias =)

escafandra 16-04-2009 14:01:05

Tendrás que escribir el evento OnDrawCell para hacer lo que quieres.

Un ejemplo de como hacerlo:

Código:

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  // Esto rellena con cadenas de distinta longitud
  for(int n=0; n<5; n++){
    StringGrid1->Cells[0][n] = "Hola " + IntToStr(n*n*n*n*n);
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
  TStringGrid *grid = dynamic_cast<TStringGrid*>(Sender);
  HDC dc = grid->Canvas->Handle;
  char *Cadena = grid->Cells[ACol][ARow].c_str();

  if(State.Contains(gdFixed)){
      grid->Canvas->Brush->Color = StringGrid1->FixedColor;
      grid->Canvas->FillRect(Rect);
  }

  grid->Canvas->Brush->Style = bsClear;
  DrawText(dc, Cadena, strlen(Cadena), &Rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
}
//---------------------------------------------------------------------------

Saludos.

BC++ 16-04-2009 16:49:04

Duda con StringGrid
 
gENIO , IDOLO!

MUY BUENA RESPUESTA! =)

SE AGRADECE.

saludos


La franja horaria es GMT +2. Ahora son las 19:37:24.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi