Vista가 네이티브 컨트롤에서보기가 변경되면 알림 (MCM_VIEWCHANGE)을 전송하기 때문에 기술적으로 가능합니다. 이 알림을 캡처하여 이벤트로 바꿀 수 있습니다. 프로젝트에 새 클래스를 추가하고 아래 표시된 코드를 붙여 넣습니다. 나는 첫날을 선택하는 코드를 미리 요리했다. 엮다. 새 컨트롤을 도구 상자의 위쪽에서 폼으로 끌어다 놓습니다. Windows 8에서 테스트 한 결과 Vista 및 Win7에서 제대로 작동하는지 확인해야합니다.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
class MonthCalendarEx : MonthCalendar {
public enum View { Month, Year, Decade, Century };
public class ViewEventArgs : EventArgs {
public ViewEventArgs(View newv, View oldv) { NewView = newv; OldView = oldv; }
public View NewView { get; private set; }
public View OldView { get; private set; }
}
public event EventHandler<ViewEventArgs> ViewChange;
protected virtual void OnViewChange(ViewEventArgs e) {
if (ViewChange == null) return;
// NOTE: I saw painting problems if this is done when MCM_VIEWCHANGE fires, delay it
this.BeginInvoke(new Action(() => {
// Select first day when switching to Month view:
if (e.NewView == View.Month) {
this.SetDate(this.GetDisplayRange(true).Start);
}
ViewChange(this, e);
}));
}
protected override void WndProc(ref Message m) {
if (m.Msg == 0x204e) { // Trap WMREFLECT + WM_NOTIFY
var hdr = (NMHDR)Marshal.PtrToStructure(m.LParam, typeof(NMHDR));
if (hdr.code == -750) { // Trap MCM_VIEWCHANGE
var vc = (NMVIEWCHANGE)Marshal.PtrToStructure(m.LParam, typeof(NMVIEWCHANGE));
OnViewChange(new ViewEventArgs(vc.dwNewView, vc.dwOldView));
}
}
base.WndProc(ref m);
}
private struct NMHDR {
public IntPtr hwndFrom;
public IntPtr idFrom;
public int code;
}
private struct NMVIEWCHANGE {
public NMHDR hdr;
public View dwOldView;
public View dwNewView;
}
}
Win7에서 잘 작동합니다. 감사. – mcu