How to change the text color of CDateTimeCtrl?

Locked How to change the text color of CDateTimeCtrl?

  • Monday, October 31, 2011 9:04 AM
     
     

    How to change background color and text color of CDateTimeCtrl(not change the color of CMonthCalCtrl)?

    Thanks!

All Replies

  • Wednesday, April 18, 2012 7:17 PM
     
     

    we cannot change the text color but we change the background color check http://forums.codeguru.com/showthread.php?t=148381 


    www.tnvbalaji.com

  • Wednesday, April 18, 2012 9:04 PM
     
      Has Code
    Try this

    CDateTimeCtrl::SetMonthCalColor()

    // Set the color for the text in the control and 
    // assure it was set properly. Unlike the GetMonthCalCtrl() member,
    // GetMonthCalColor() and SetMonthCalColor() can be used at any time.
    m_DateTimeCtrl.SetMonthCalColor(MCSC_TEXT, RGB(255, 0, 0));
    VERIFY(m_DateTimeCtrl.GetMonthCalColor(MCSC_TEXT) == RGB(255, 0, 0));

    Thanks


    Rupesh Shukla


  • Wednesday, April 25, 2012 1:22 PM
     
     

    Did you solved your problem.

    Thanks


    Rupesh Shukla

  • Thursday, April 26, 2012 5:58 PM
     
     

    How to change background color and text color of CDateTimeCtrl(not change the color of CMonthCalCtrl)?

    Sample code posted by Rupesh will change calendar's text color but it will not change color of the time picker as you requested.

    Another thing to be aware of is this: Rupesh’s code will work only on pre-Vista windows. In Vista and later, this code will work only if windows theme is set to "Windows Classic".

    I am going to check the link you posted and as soon as I know anything I will get back to you.


    JohnCz


    • Edited by JohnCz Thursday, April 26, 2012 5:58 PM
    •  
  • Thursday, April 26, 2012 10:06 PM
     
     

    I have checked check http://forums.codeguru.com/showthread.php?t=148381 link and tried the code.
    It does not work even if I set windows to classic.

    However I have tried to handle WM_PAINT message to do all drawings and it looks promising. The thing is you would have to handle all drawing: background fill, text and button drawing.

    I think this is the only way to achieve what you want.


    JohnCz

  • Friday, April 27, 2012 1:54 PM
     
     

    Sample code posted by Rupesh will change calendar's text color but it will not change color of the time picker as you requested.


    JohnCz


    Just had gone through the title of the thread . So i just mentioned how to change the text color.Actually we can change the background color too in different way . Let me verify it once again and will back to this thread. May be i can put some more inut in this thread

    Thanks


    Rupesh Shukla

  • Sunday, April 29, 2012 12:52 PM
     
     

    Even though it is possible, it is not practical.

    It can be achieved by either drawing the whole control or parts of it. I have tried to let control draw drop down button and then fill rectangle to erase text drawn by the control and draw text using color I designated. As it turns, it is quite a challenge: too many variables.

    Each window version draws control slightly different, using different sizes of the drop down button and different interpretation of the windows styles.
    For example, in Windows 2004, border is part of the non-client area. Windows 2008 draws border and the whole window is a client area.
    In conclusion: do not try to change the color unless you are going to develop tour own control working up to each Windows version standard.


    JohnCz


    • Edited by JohnCz Sunday, April 29, 2012 1:04 PM
    •  
  • Monday, April 30, 2012 7:18 PM
     
     

    John i didn't tried it by myself . Just want to try nothing else . This is what i am doing from last couple of month creating custom control  .Seems OP is not inetersted in this thread anymore .So lets close it here .

    Thanks


    Rupesh Shukla

  • Monday, April 30, 2012 11:25 PM
     
     
    Could not agree more.

    JohnCz