Remplissage des cellules

De RAD Studio
Aller à : navigation, rechercher

Remonter à Personnalisation d'une grille - Index

Un contrôle grille se remplit cellule par cellule. S'agissant du calendrier, cela revient à calculer une date (si elle existe) pour chaque cellule. Le dessin par défaut des cellules de la grille s'opère dans une méthode virtuelle intitulée DrawCell.

Pour remplir le contenu des cellules de la grille, vous devez redéfinir la méthode DrawCell.

Les cellules de titre de la ligne fixe sont ce qu'il y a de plus facile à remplir. La bibliothèque d'exécution contient un tableau avec l'intitulé raccourci des jours et il vous faut donc insérer l'intitulé approprié à chaque colonne :



type
  TSampleCalendar = class(TCustomGrid)
  protected
    procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
      override;
  end;
.
.
.
procedure TSampleCalendar.DrawCell(ACol, ARow: Longint; ARect: TRect;
  AState: TGridDrawState);
begin
  if ARow = 0 then
    Canvas.TextOut(ARect.Left, ARect.Top, ShortDayNames[ACol + 1]);    { use RTL strings }
end;



void __fastcall TSampleCalendar::DrawCell(int ACol, int ARow, const Windows::TRect &ARect,
  TGridDrawState AState)
{
  String TheText;
  int TempDay;
  if (ARow == 0) TheText = ShortDayNames[ACol + 1];
  else
  {
    TheText = "";
    TempDay = DayNum(ACol, ARow);                   // DayNum is defined later
    if (TempDay != -1) TheText = IntToStr(TempDay);
  }
  Canvas->TextRect(ARect, ARect.Left + (ARect.Right - ARect.Left
   - Canvas->TextWidth(TheText)) / 2,
  ARect.Top + (ARect.Bottom - ARect.Top - Canvas->TextHeight(TheText)) / 2, TheText);
}

Rubriques

Voir aussi