RE: DateTimePicker wrongly displays MinDate when dropdown is pressed.
- From: v-zhye@xxxxxxxxxxxxxxxxxxxx (Zhi-xin Ye)
- Date: Tue, 05 Aug 2008 08:08:19 GMT
Dear Julian,
I can reproduce this problem on Vista, however the same code works fine on
XP/Windows2003.
It seems on Vista, the underlying Windows MonthCalendar control has been
changed.
Someone had been reported this problem to our Connect feekback portal at:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedba
ckID=358654&wa=wsignin1.0
After doing some research on this problem, I find out a way to prevent this
behavior.
=====Solution=====
private void Form1_Load(object sender, EventArgs e)
{
d = this.dateTimePicker1.MinDate;
this.dateTimePicker1.CloseUp += new
EventHandler(dateTimePicker1_CloseUp);
this.dateTimePicker1.DropDown += new
EventHandler(dateTimePicker1_DropDown);
}
DateTime d;
void dateTimePicker1_CloseUp(object sender, EventArgs e)
{
d = this.dateTimePicker1.Value;
}
void dateTimePicker1_DropDown(object sender, EventArgs e)
{
//Reset value for the DateTimePicker control
this.dateTimePicker1.Value = d;
//retrieve the handle of the MonthCalendar in the DateTimePicker
IntPtr p =
SendMessage(this.dateTimePicker1.Handle,DTM_GETMONTHCAL,0,0);
//Re-select the date on the MonthCalendar
SYSTEMTIME t = DateTimeToSysTime(new DateTime(d.Year, d.Month,
d.Day));
SendMessage(p, MCM_SETCURSEL, 0, t);
}
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam,
int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int
wParam, SYSTEMTIME lParam);
private const int DTM_FIRST = 0x1000;
private const int DTM_GETMONTHCAL = (DTM_FIRST + 8);
private const int MCM_SETCURSEL = 0x1002;
[StructLayout(LayoutKind.Sequential)]
public class SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
private SYSTEMTIME DateTimeToSysTime(DateTime time)
{
return new SYSTEMTIME {
wYear = (short)time.Year,
wMonth = (short)time.Month,
wDayOfWeek = (short)time.DayOfWeek,
wDay = (short)time.Day,
wHour = (short)time.Hour,
wMinute = (short)time.Minute,
wSecond = (short)time.Second,
wMilliseconds = 0 };
}
===Documents for your information===
MCM_SETCURSEL Message
http://msdn.microsoft.com/en-us/library/bb761002(VS.85).aspx
If you need further help on this, please feel free to let me know.
Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- RE: DateTimePicker wrongly displays MinDate when dropdown is press
- From: Julian Ladbury
- RE: DateTimePicker wrongly displays MinDate when dropdown is press
- Prev by Date: Re: Dropping Controls On To User Control At Design Time
- Next by Date: Re: Dropping Controls On To User Control At Design Time
- Previous by thread: Dropping Controls On To User Control At Design Time
- Next by thread: RE: DateTimePicker wrongly displays MinDate when dropdown is press
- Index(es):
Relevant Pages
|
Loading