2010-11-19 40 views
1

我正在使用Delphi7。手動刷新BoldDays的TMonthCalendar?

我知道我可以在TMonthCalendar的OnGetMonthInfo事​​件中使用BoldDays傳遞一個我想以粗體顯示的日期數組。

我的問題是,如果新的日曆條目保存,我不能手動調用OnGetMonthInfo事​​件。

使用

MyCalendar.Date:=IncMonth(MyCalendar.Date, -1); 
    MyCalendar.Date:=IncMonth(MyCalendar.Date, 1); 

將刷新日曆和加粗個月,但在Vista和Windows7這將產生日曆的一個惱人的「滾動」的效果。

有沒有辦法更新它沒有「特殊效果」?

謝謝!

回答

2

您可以通過發送MCM_SETDAYSTATE消息來強制刷新當前顯示的日曆。

除了代碼以GetMonthInfo事​​件

procedure TForm1.GetMonthBoldInfo(month:cardinal):cardinal; 
begin 
    ... 
end; 

procedure TForm1.MonthCalendar1GetMonthInfo(Sender: TObject; 
      Month: Cardinal; var MonthBoldInfo: Cardinal); 
begin 
    monthBoldInfo:=GetMonthBoldInfo(month); 
end; 

你需要一些代碼,當日歷項改變刷新迴應...

var DayStates: array[0..2] of integer; 
.... 
DayStates[0]:=GetMonthBoldInfo(month-1); 
DayStates[1]:=GetMonthBoldInfo(month); 
DayStates[2]:=GetMonthBoldInfo(month+1); 
SendMessage(MonthCalendar1.Handle, MCM_SETDAYSTATE, 3, longint(@DayStates));