none
WHY? DO NOT CHANGE THE COLOR DATETIMEPICKER RRS feed

  • Question

  • Hi how are you all,I've been programming for a short time in vb and i am trying to change the appearance color of DATETIMEPICKER in the form but when i change the properties of color nothing happens, why? is that. I have had very little help in the Spanish forum, so i try in English. Thanks a lot and sorry for the inconvenience
    Saturday, May 12, 2018 1:06 PM

Answers

  •  Disable the Visual Style for the MonthCal in the DropDown event if you want to change its colors :
    Private Sub DateTimePicker1_DropDown(sender As Object, e As EventArgs) Handles DateTimePicker1.DropDown
        Dim hWndMonthCal = SendMessage(DateTimePicker1.Handle, DTM_GETMONTHCAL, 0, 0)
        SetWindowTheme(hWndMonthCal, "", "")
    End Sub

    with :

        <DllImport("Uxtheme.dll", SetLastError:=True)>
        Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal pszSubAppName As String, ByVal pszSubIdList As String) As Integer
        End Function
    
        <DllImport("User32.dll", EntryPoint:="SendMessageW", SetLastError:=True)>
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
        End Function
    
        Public Const DTM_FIRST As Integer = &H1000
        Public Const DTM_GETMONTHCAL As Integer = (DTM_FIRST + 8)

    Saturday, May 12, 2018 2:01 PM
  • When XP Visual Styles are enabled, it overrides these custom settings.  You can turn this off in My Project  -> Application tab, but there will be other consequences to the look of the form.  I'm not sure if there is a way to just modify a single control...

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Saturday, May 12, 2018 1:18 PM
    Moderator
  • Visuall styles can be enabled/disabled for individual windows using their native window handles. The docs were written for C/C++ but you should be able to call SetWindowTheme using P/INvoke.  See Enabling Visual Styles which says -

    Turning Off Visual Styles

    You can turn off visual styles for a control or for all controls in a window by calling the SetWindowTheme function as follows:

    SetWindowTheme(hwnd, L" ", L" ");
    
    
    

    In the previous example, hwnd is the handle of the window in which to disable visual styles. After the call, the control renders without visual styles.

    -------

    If I remember correctly there should be posts in the forums about doing this with the DateTimePicker control (and there is more than one HWND in the control).





    • Edited by RLWA32 Saturday, May 12, 2018 1:34 PM added comment
    • Marked as answer by Principiante1040Vb Saturday, May 12, 2018 2:01 PM
    Saturday, May 12, 2018 1:26 PM

All replies

  • When XP Visual Styles are enabled, it overrides these custom settings.  You can turn this off in My Project  -> Application tab, but there will be other consequences to the look of the form.  I'm not sure if there is a way to just modify a single control...

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Saturday, May 12, 2018 1:18 PM
    Moderator
  • Visuall styles can be enabled/disabled for individual windows using their native window handles. The docs were written for C/C++ but you should be able to call SetWindowTheme using P/INvoke.  See Enabling Visual Styles which says -

    Turning Off Visual Styles

    You can turn off visual styles for a control or for all controls in a window by calling the SetWindowTheme function as follows:

    SetWindowTheme(hwnd, L" ", L" ");
    
    
    

    In the previous example, hwnd is the handle of the window in which to disable visual styles. After the call, the control renders without visual styles.

    -------

    If I remember correctly there should be posts in the forums about doing this with the DateTimePicker control (and there is more than one HWND in the control).





    • Edited by RLWA32 Saturday, May 12, 2018 1:34 PM added comment
    • Marked as answer by Principiante1040Vb Saturday, May 12, 2018 2:01 PM
    Saturday, May 12, 2018 1:26 PM
  • Disable the Visual Style for the MonthCal if you want to change its colors :

    Dim hWndMonthCal = SendMessage(datetimePicker.Handle, DTM_GETMONTHCAL, 0, 0)
    SetWindowTheme(hWndMonthCal, "", "")

    with :

        <DllImport("Uxtheme.dll", SetLastError:=True)>
        Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal pszSubAppName As String, ByVal pszSubIdList As String) As Integer
        End Function
    
        <DllImport("User32.dll", EntryPoint:="SendMessageW", SetLastError:=True)>
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
        End Function
    
        Public Const DTM_FIRST As Integer = &H1000
        Public Const DTM_GETMONTHCAL As Integer = (DTM_FIRST + 8)

    Saturday, May 12, 2018 1:51 PM
  •  Disable the Visual Style for the MonthCal in the DropDown event if you want to change its colors :
    Private Sub DateTimePicker1_DropDown(sender As Object, e As EventArgs) Handles DateTimePicker1.DropDown
        Dim hWndMonthCal = SendMessage(DateTimePicker1.Handle, DTM_GETMONTHCAL, 0, 0)
        SetWindowTheme(hWndMonthCal, "", "")
    End Sub

    with :

        <DllImport("Uxtheme.dll", SetLastError:=True)>
        Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal pszSubAppName As String, ByVal pszSubIdList As String) As Integer
        End Function
    
        <DllImport("User32.dll", EntryPoint:="SendMessageW", SetLastError:=True)>
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
        End Function
    
        Public Const DTM_FIRST As Integer = &H1000
        Public Const DTM_GETMONTHCAL As Integer = (DTM_FIRST + 8)

    Saturday, May 12, 2018 2:01 PM
  • Thanks a lot

    Saturday, May 12, 2018 2:02 PM
  • Thanks a lot
    Saturday, May 12, 2018 2:04 PM