1

我正在尝试删除显示在 datetimepicker 控件底部的 Today 链接。我发现了一个与代码类似的问题,但这似乎不起作用 - 我的转换是否存在问题,或者这种方法不再有效(Visual Studio 2012)?

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

来源:如何从 DateTimePicker 控件(Windows 窗体控件)中删除“今天”按钮

4

1 回答 1

1

您没有发送样式:

改变这个:

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

对此:

SendMessage(Me.Handle, DTM_SETMCSTYLE, IntPtr.Zero, CType(style, IntPtr))
于 2013-02-01T21:09:45.687 回答