|
Could you please help .
How do the winform call this class>
or How do the calender call ondropdown function ?
Thanks
|
|
|
|
|
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Class ExtendedDateTimePicker : Inherits DateTimePicker
Private Declare Auto Function GetWindowLong Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal index As Int32) As Int32
Private Declare Auto Function SetWindowLong Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal index As Int32, ByVal value As Int32) As Int32
Private Const GWL_STYLE As Int32 = (-16)
Private Const MCM_FIRST As Int32 = &H1000
Private Const MCM_GETMINREQRECT As Int32 = (MCM_FIRST + 9)
Private Const MCS_WEEKNUMBERS As Int32 = &H4
Private Const DTM_FIRST As Int32 = &H1000
Private Const DTM_GETMONTHCAL As Int32 = (DTM_FIRST + 8)
Private Declare Auto Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal msg As Int32, ByVal param As Int32, ByVal data As Int32) As IntPtr
Private Declare Auto Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal msg As Int32, ByVal param As Int32, ByRef data As Rectangle) As Int32
Private Declare Auto Function MoveWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal x As Int32, ByVal y As Int32, ByVal width As Int32, ByVal height As Int32, ByVal repaint As Boolean) As Int32
Private _ShowWeekNumbers As Boolean
<Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property ShowWeekNumbers() As Boolean
Get
Return _ShowWeekNumbers
End Get
Set(ByVal value As Boolean)
_ShowWeekNumbers = value
End Set
End Property
Private Const WS_BORDER As Int32 = &H800000
Protected Overloads Overrides Sub OnDropDown(ByVal e As EventArgs)
Dim hMonthView As IntPtr = SendMessage(Me.Handle, DTM_GETMONTHCAL, 0, 0)
Dim hMonthViewParent As Int32 = GetWindowLong(hMonthView, -8)
Dim dwStyle As Int32 = GetWindowLong(hMonthView, GWL_STYLE)
If Me.ShowWeekNumbers Then
dwStyle = dwStyle Or MCS_WEEKNUMBERS Or WS_BORDER
Else
dwStyle = dwStyle And Not MCS_WEEKNUMBERS
End If
Dim rct As New Rectangle
SetWindowLong(hMonthView, GWL_STYLE, dwStyle)
SendMessage(hMonthView, MCM_GETMINREQRECT, 0, rct)
MoveWindow(hMonthViewParent, 0, 0, rct.Right, rct.Bottom, True)
MoveWindow(hMonthView, 0, 0, rct.Right, rct.Bottom, True)
MyBase.OnDropDown(e)
End Sub
End Class
modified 2-Nov-16 10:49am.
|
|
|
|
|
When I set MaxDate property for the DateTimePicker it doesn't calculates week number for not available weeks correctly. For example week 20 is first in the month, if to set MaxDate during this week all next weeks will be also 20. Any workaround?
|
|
|
|
|
Did you find a solution for this? I've been searching for hours without finding an answer
|
|
|
|
|
Hello here a solution for Windows Vista and Windows 7.
The Bold text is the change from the original code
C#
private const Int32 WS_BORDER = 0x800000;
protected override void OnDropDown(EventArgs e)
{
IntPtr hMonthView = SendMessage(this.Handle, DTM_GETMONTHCAL, 0, 0);
Int32 hMonthViewParent = GetWindowLong(hMonthView, -8);
Int32 dwStyle = GetWindowLong(hMonthView, GWL_STYLE);
if (this.ShowWeekNumbers) {
dwStyle = dwStyle | MCS_WEEKNUMBERS | WS_BORDER;
} else {
dwStyle = dwStyle & !MCS_WEEKNUMBERS;
}
Rectangle rct = new Rectangle();
SetWindowLong(hMonthView, GWL_STYLE, dwStyle);
SendMessage(hMonthView, MCM_GETMINREQRECT, 0, rct);
MoveWindow(hMonthViewParent, 0, 0, rct.Right, rct.Bottom, true);
MoveWindow(hMonthView, 0, 0, rct.Right, rct.Bottom, true);
base.OnDropDown(e);
}
VB
Private Const WS_BORDER As Int32 = &H800000
Protected Overloads Overrides Sub OnDropDown(ByVal e As EventArgs)
Dim hMonthView As IntPtr = SendMessage(Me.Handle, DTM_GETMONTHCAL, 0, 0)
Dim hMonthViewParent As Int32 = GetWindowLong(hMonthView, -8)
Dim dwStyle As Int32 = GetWindowLong(hMonthView, GWL_STYLE)
If Me.ShowWeekNumbers Then
dwStyle = dwStyle Or MCS_WEEKNUMBERS Or WS_BORDER
Else
dwStyle = dwStyle And Not MCS_WEEKNUMBERS
End If
Dim rct As New Rectangle
SetWindowLong(hMonthView, GWL_STYLE, dwStyle)
SendMessage(hMonthView, MCM_GETMINREQRECT, 0, rct)
MoveWindow(hMonthViewParent, 0, 0, rct.Right, rct.Bottom, True)
MoveWindow(hMonthView, 0, 0, rct.Right, rct.Bottom, True)
MyBase.OnDropDown(e)
End Sub
Greetz Andree
modified 2-Jul-13 10:05am.
|
|
|
|
|
I don't really know C# well but I needed to change your function to make it work:
private const Int32 WS_BORDER = 0x800000;
private const int GWL_HWNDPARENT = (-8);
protected override void OnDropDown(EventArgs e)
{
IntPtr hMonthView = SendMessage(this.Handle, DTM_GETMONTHCAL, 0, 0);
Int32 hMonthViewParent = GetWindowLong(hMonthView, GWL_HWNDPARENT);
Int32 dwStyle = GetWindowLong(hMonthView, GWL_STYLE);
if (this.ShowWeekNumbers)
{
dwStyle = dwStyle | MCS_WEEKNUMBERS | WS_BORDER;
}
else
{
dwStyle = dwStyle & ~MCS_WEEKNUMBERS;
}
Rectangle rct = new Rectangle();
SetWindowLong(hMonthView, GWL_STYLE, dwStyle);
SendMessage(hMonthView, MCM_GETMINREQRECT, 0, ref rct);
MoveWindow((IntPtr)hMonthViewParent, 0, 0, rct.Right, rct.Bottom, true);
MoveWindow(hMonthView, 0, 0, rct.Right, rct.Bottom, true);
base.OnDropDown(e);
}
|
|
|
|
|
|
is it possible to display the week numbers in the form of iso8601?
|
|
|
|
|
What do you mean? Please, supply an example.
|
|
|
|
|
Forexample Run this code Windows7 and windows XP any europe culture (My Culture tr-TR). Today (10.04.2012), Win7 WeekNumber = 16, Win XP Week Number = 15 . WinXP is ISO Standard.
|
|
|
|
|
|
I found a Bug in the Windows API on Windows 7, 8 and 8.1
Windows 10 works correct.
All German Countrys use ISO 8601 but on Region setting "German (Austria)" the week number is Wrong.
I changed the Region format to "German (Germany)" and everything works fine.
Maybe that is also an option for other Countrys...
|
|
|
|
|
Simple it works fine with VS2010 framwork 4.0
|
|
|
|
|
It could really use some comments to understand what it actually does at some lines, but copying it in a project and using it, it "just works", so it's pretty fine.
|
|
|
|
|
Hello sir.. can you convert your code to vb .net 2008.?
Thank you sir.
GodBless
|
|
|
|
|
I do not think it is that much comlicated
see my work arround for displying week number
Swich on custom format in the desinger
Put this code in form load
DTPWeek1.Value=Now.Date
add this method for value changed event
sub DTPWeek1_ValueChanged ( ...) handles DTPWeek1.ValueChanged
DTPWeek1.CustomFormat= "'" + DatePart(DateInterval.Year ,DTPWeek1.value ).Tostring & " week " & DatePart(DateInterval.WeekofYear ,DTPWeek1.value ).Tostring & "'"
end sub
And this method is known as using body text Datetime picker control and it is a must body
To be inside quotes like 'bodytext'
regards
john
|
|
|
|
|
I was vary happy about finding this very usefull component, but i'm having a trouble using some other functionality coming from the original dateTimePicker :
Activating the checkbox intergrated with DateTimePicker, but while checking/unchecking the checkbox, the binded value is always the same of the original value (a get access is done at the popertie, before set)
I've verified that this functionality work great with the original datetimepicker.
Any idea welcome.
|
|
|
|
|
HI,
Can u send me this sample project. Please help.
My mail id : jawahar_csc@yahoo.co.in
Thanks in advance.
|
|
|
|
|
HI all,
this is a great utility class and provides exactly the functionality I am looking for, but in the drop down part, the right most column is shown only half... how do I change the width of the drop down part of the DateTimePicker?
http://www.moccasoft.de/test/extDateTimePicker.gif
Thanks!
Axxx
|
|
|
|
|
Hi,
I got the same problem when moving to Vista (Business in my case). Try this (I've resized the parent too):
protected override void OnDropDown(EventArgs e)<br />
{<br />
IntPtr monthView = SendMessage(Handle, DTM_GETMONTHCAL, 0, 0);<br />
IntPtr monthViewParent = GetParent(monthView);<br />
<br />
int style = GetWindowLong(monthView, GWL_STYLE);<br />
if (ShowWeekNumbers)<br />
{<br />
style = style | MCS_WEEKNUMBERS;<br />
}<br />
else<br />
{<br />
style = style & ~MCS_WEEKNUMBERS;<br />
}<br />
Rectangle rect = new Rectangle();<br />
SetWindowLong(monthView, GWL_STYLE, style);<br />
SendMessage(monthView, MCM_GETMINREQRECT, 0, ref rect);<br />
MoveWindow(monthView, 0, 0, rect.Right + 2, rect.Bottom+2, true);<br />
MoveWindow(monthViewParent, 0, 0, rect.Right + 2, rect.Bottom+2, true);<br />
<br />
base.OnDropDown(e);<br />
}
|
|
|
|
|
You are The King....
I'm working in VB.NET so
MyBase.OnDropDown(e); caused hang, but - it works nicely.
I thought there is some window that overlaps it, but...
Thanks
|
|
|
|
|