2013-02-01 69 views
1

我試圖刪除顯示在datetimepicker控件底部的Today鏈接。 我用代碼發現了一個類似的問題,但這似乎不起作用 - 我的轉換是否存在問題,或者此方法不再有效(Visual Studio 2012)?Winforms:從DateTimePicker中刪除「Today」

Class MyDateTimePicker 
Inherits DateTimePicker 
Protected Overrides Sub OnHandleCreated(e As EventArgs) 
    Dim style As Integer = CInt(SendMessage(Me.Handle, DTM_GETMCSTYLE, IntPtr.Zero, IntPtr.Zero)) 
    style = style Or MCS_NOTODAY Or MCS_NOTODAYCIRCLE 
    SendMessage(Me.Handle, DTM_SETMCSTYLE, IntPtr.Zero, CType(0, IntPtr)) 
    MyBase.OnHandleCreated(e) 
End Sub 

Private Const DTM_FIRST As Integer = &H1000 
Private Const DTM_SETMCSTYLE As Integer = DTM_FIRST + 11 
Private Const DTM_GETMCSTYLE As Integer = DTM_FIRST + 12 
Private Const MCS_NOTODAYCIRCLE As Integer = &H8 
Private Const MCS_NOTODAY As Integer = &H10 

<DllImport("user32.dll")> _ 
Private Shared Function SendMessage(hWnd As IntPtr, msg As Integer, wp As IntPtr, lp As IntPtr) As IntPtr 
End Function 
End Class 

來源:How can I remove the "Today" button from DateTimePicker control (of Windows form Control)

+0

沒有,目前仍然可以工作在VS2012和Win8中罰款。但是,您沒有正確複製代碼。使用CType(style,IntPtr),而不是0。 –

回答

1

你是不是送的樣式:

更改此:

SendMessage(Me.Handle, DTM_SETMCSTYLE, IntPtr.Zero, CType(0, IntPtr)) 

這樣:

SendMessage(Me.Handle, DTM_SETMCSTYLE, IntPtr.Zero, CType(style, IntPtr))