RAD Studio
ContentsIndex
PreviousUpNext
Selecting the Current Day

Now that you have numbers in the calendar cells, it makes sense to move the selection highlighting to the cell containing the current day. By default, the selection starts on the top left cell, so you need to set the Row and Column properties both when constructing the calendar initially and when the date changes. 

To set the selection on the current day, change the UpdateCalendar method to set Row and Column before calling Refresh:

procedure TSampleCalendar.UpdateCalendar;
begin
  if FDate <> 0 then
  begin
    .  { existing statements to set FMonthOffset }
    .
    .
    Row := (ADay - FMonthOffset) div 7 + 1;
    Col := (ADay - FMonthOffset) mod 7;
  end;
  Refresh; { this is already here }
end;

 

void __fastcall TSampleCalendar::UpdateCalendar(void)
{
  unsigned short AYear, AMonth, ADay;
  TDateTime FirstDate;                  
  if ((int) FDate != 0)                          
  {
  .
  .
  .                                            // existing statements to set FMonthOffset
    Row = (ADay - FMonthOffset) / 7 + 1;
    Col = (ADay - FMonthOffset) % 7;
  }
  Refresh();                                  // this is already here
}

Note that you are now reusing the ADay variable previously set by decoding the date.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!