读书人

使用日历控件MonthCalendar选择日期时

发布时间: 2013-07-11 15:38:46 作者: rapoo

使用日历控件MonthCalendar选择日期时,怎么知道鼠标点的是日期还是上边变换月份的小按钮?
使用日历控件MonthCalendar选择日期时,怎么知道鼠标点的是日期还是上边变换月份的小按钮?
请大虾指点,谢谢!!!
[解决办法]
不如说说你想干什么,是想知道当前选择的月份是否变化还是怎样?
[解决办法]

引用:
目的:单击日期就将日期放到Edit中,并关闭MonthCalendar。
点两个小按钮就翻页换月份,不关闭MonthCalendar。


改用DateTimePicker吧
[解决办法]
引用:
我想用MonthCalendar做个有点特色的东西,我们用的软件中到处能看到。DateTimePicker太平常,并且它的哪个显示框还不能清空。
MonthCalendar中的星期一、星期二怎么变成一、二?


没办法了,MonthCalendar是调用操作系统定义的类SysMonthCal32创建的控件,他的字体和重画都是系统后台在出处理,只提供了几个消息接口给外界设置他的一些属性,Delphi没法处理他的重画事件;
消息接口你可以参考CommCtrl单元下的几个函数,我看过了,没有设置你想要的功能的接口。


// returns FALSE if MCS_MULTISELECT
// returns TRUE and sets *pst to the currently selected date otherwise
{$EXTERNALSYM MonthCal_GetCurSel}
function MonthCal_GetCurSel(hmc: HWND; var pst: TSystemTime): BOOL;

// returns FALSE if MCS_MULTISELECT
// returns TURE and sets the currently selected date to *pst otherwise
{$EXTERNALSYM MonthCal_SetCurSel}
function MonthCal_SetCurSel(hmc: HWND; const pst: TSystemTime): BOOL;

// returns the maximum number of selectable days allowed
{$EXTERNALSYM MonthCal_GetMaxSelCount}
function MonthCal_GetMaxSelCount(hmc: HWND): DWORD;

// sets the max number days that can be selected iff MCS_MULTISELECT
{$EXTERNALSYM MonthCal_SetMaxSelCount}
function MonthCal_SetMaxSelCount(hmc: HWND; n: UINT): BOOL;

// sets rgst[0] to the first day of the selection range
// sets rgst[1] to the last day of the selection range


{$EXTERNALSYM MonthCal_GetSelRange}
function MonthCal_GetSelRange(hmc: HWND; rgst: PSystemTime): BOOL;

// selects the range of days from rgst[0] to rgst[1]
{$EXTERNALSYM MonthCal_SetSelRange}
function MonthCal_SetSelRange(hmc: HWND; rgst: PSystemTime): BOOL;

// if rgst specified, sets rgst[0] to the starting date and
// and rgst[1] to the ending date of the the selectable (non-grayed)
// days if GMR_VISIBLE or all the displayed days (including grayed)
// if GMR_DAYSTATE.
// returns the number of months spanned by the above range.
{$EXTERNALSYM MonthCal_GetMonthRange}
function MonthCal_GetMonthRange(hmc: HWND; gmr: DWORD; rgst: PSystemTime): DWORD;

// cbds is the count of DAYSTATE items in rgds and it must be equal
// to the value returned from MonthCal_GetMonthRange(hmc, GMR_DAYSTATE, NULL)
// This sets the DAYSTATE bits for each month (grayed and non-grayed
// days) displayed in the calendar. The first bit in a month's DAYSTATE
// corresponts to bolding day 1, the second bit affects day 2, etc.
{$EXTERNALSYM MonthCal_SetDayState}
function MonthCal_SetDayState(hmc: HWND; cbds: Integer; const rgds: TNMDayState): BOOL;

// sets prc the minimal size needed to display one month
{$EXTERNALSYM MonthCal_GetMinReqRect}
function MonthCal_GetMinReqRect(hmc: HWND; var prc: TRect): BOOL;

// set what day is "today" send NULL to revert back to real date
{$EXTERNALSYM MonthCal_SetToday}
function MonthCal_SetToday(hmc: HWND; const pst: TSystemTime): BOOL;

// get what day is "today"
// returns BOOL for success/failure
{$EXTERNALSYM MonthCal_GetToday}
function MonthCal_GetToday(hmc: HWND; var pst: TSystemTime): BOOL;

// determine what pinfo->pt is over


{$EXTERNALSYM MonthCal_HitTest}
function MonthCal_HitTest(hmc: HWND; var info: TMCHitTestInfo): DWORD;

// set colors to draw control with -- see MCSC_ bits below
{$EXTERNALSYM MonthCal_SetColor}
function MonthCal_SetColor(hmc: HWND; iColor: Integer; clr: TColorRef): TColorRef;

{$EXTERNALSYM MonthCal_GetColor}
function MonthCal_GetColor(hmc: HWND; iColor: Integer): TColorRef;

// set first day of week to iDay:
// 0 for Monday, 1 for Tuesday, ..., 6 for Sunday
// -1 for means use locale info
{$EXTERNALSYM MonthCal_SetFirstDayOfWeek}
function MonthCal_SetFirstDayOfWeek(hmc: HWND; iDay: Integer): Integer;

// DWORD result... low word has the day. high word is bool if this is app set
// or not (FALSE == using locale info)
{$EXTERNALSYM MonthCal_GetFirstDayOfWeek}
function MonthCal_GetFirstDayOfWeek(hmc: HWND): Integer;

// modifies rgst[0] to be the minimum ALLOWABLE systemtime (or 0 if no minimum)
// modifies rgst[1] to be the maximum ALLOWABLE systemtime (or 0 if no maximum)
// returns GDTR_MIN
[解决办法]
GDTR_MAX if there is a minimum
[解决办法]
maximum limit
{$EXTERNALSYM MonthCal_GetRange}
function MonthCal_GetRange(hmc: HWND; rgst: PSystemTime): DWORD;

// if GDTR_MIN, sets the minimum ALLOWABLE systemtime to rgst[0], otherwise removes minimum
// if GDTR_MAX, sets the maximum ALLOWABLE systemtime to rgst[1], otherwise removes maximum
// returns TRUE on success, FALSE on error (such as invalid parameters)
{$EXTERNALSYM Monthcal_SetRange}
function Monthcal_SetRange(hmc: HWND; gdtr: DWORD; rgst: PSystemTime): BOOL;

// returns the number of months one click on a next/prev button moves by
{$EXTERNALSYM MonthCal_GetMonthDelta}
function MonthCal_GetMonthDelta(hmc: HWND): Integer;



// sets the month delta to n. n = 0 reverts to moving by a page of months
// returns the previous value of n.
{$EXTERNALSYM MonthCal_SetMonthDelta}
function MonthCal_SetMonthDelta(hmc: HWND; n: Integer): Integer;

// sets *psz to the maximum width/height of the "Today" string displayed
// at the bottom of the calendar (as long as MCS_NOTODAY is not specified)
{$EXTERNALSYM MonthCal_GetMaxTodayWidth}
function MonthCal_GetMaxTodayWidth(hmc: HWND): DWORD;

{$EXTERNALSYM MonthCal_SetUnicodeFormat}
function MonthCal_SetUnicodeFormat(hwnd: HWND; fUnicode: BOOL): BOOL;

{$EXTERNALSYM MonthCal_GetUnicodeFormat}
function MonthCal_GetUnicodeFormat(hwnd: HWND): BOOL;


[解决办法]

var
m: Cardinal = 0;
b: Boolean = False; // 如果为true表示月份改变了,相当点击了左右选择月份的按钮

// OnGetMonthInfo 事件
procedure TForm1.monthCalendar1GetMonthInfo(Sender: TObject; Month: Cardinal;
var MonthBoldInfo: Cardinal);
begin
b := m <> Month;
end;

[解决办法]
引用:

var
m: Cardinal = 0;
b: Boolean = False; // 如果为true表示月份改变了,相当点击了左右选择月份的按钮

// OnGetMonthInfo 事件
procedure TForm1.monthCalendar1GetMonthInfo(Sender: TObject; Month: Cardinal;
var MonthBoldInfo: Cardinal);
begin
b := m <> Month;
end;


这个事件不行,只要年份或者月份变了就会触发。如果你点击灰色显示的日期也会触发。
[解决办法]
难道没有解决的方法?期待高手。
[解决办法]
想要有特色,就自己写个这个控件了

读书人网 >.NET

热点推荐