Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
275
UltraDateTimeEditor not using Style Library Roles
posted

Hi,

I have an UltraDateTimeEditor control on a form. I have defined the  DotNetMonthDropDown and DotNetMonthDropDownTitle roles in my Style Library. However, these settings are not being used and all I see is the default calendar style. I have also defined the Inbox MonthCalendar roles. Nothings seems to work. Does anybody have any idea how to get this to work?

  • 469350
    Offline posted

    Hi Tracy, 

    I tried this out and it's a bit complicated. The UltraDateTimeEditor uses the Microsoft MonthCalendar control as it's dropdown. That control was changed by Microsoft a few years ago to pick up a new visual style from the operating system settings. 

    Microsoft explains the details here:

    https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-change-monthcalendar-control-appearance

    The screen shots you attached here show, as far as I can tell: 

    1) The UltraDateTimePicker using the older style MonthDropDown. 

    2) The MonthDropDown control using the older style MonthDropDown. 

    3) The UltraDateTimeEditor using the new visual style. 

    In case #3, the DotNetMonthDropDown and DotNetMonthDropDownTitle will always be ignored, because these roles work by setting properties on the MonthDropDown such as TitleBackColor and TitleForeColor. And those properties are ignored by the control itself when using the new style. 

    In case #1, these roles DO work for me in my testing. Presuambly, in your first screen shot, you have commented out (or removed) the call to Application.EnableVisualStyles(), so I'm not sure why it's not working for you. 

    Case #2 does not work for me, because AppStylist simply doesn't support styling the standalone MonthDropDown via the UIRoles. This is probably an artifact of how the DotNetMonthDropDown and DotNetMonthDropDownTitle were added. I think these roles were added later, as a result of the fact that the DateTimeEditor is used in the grid, and there's no way to style the MonthDropDown in a grid without them. But there already existed a way to style the standalone MonthDropDown control via the Component Roles. The caveat is that you need to have an InboxControlStyle on the form, which is a component that allows styling to apply to Inbox controls. 

    Anyway... If you want your calendars to always have a consistent look and pick up the styling from your style library, there are 2 ways you can go: 

    1) Turn off EnabledVisualStyles. As I mentioned, you seem to already be doing this, so I'm not sure why it's not working for you. It's definitely working for me. So if it's not working for you, maybe you can try it out in a small sample project and send it to me along with your isl and I can check it out and see what's going on. 

    With this approach, if you are using standalone MonthCalendars in your application, then you will also want to put an InboxControlStyler on your form and make sure your style library also sets the ComponentRole settings on the MonthCalendar so it matches the UIRoles. 

    2) Use UltraCalendarCombo instead of UltraDateTimeEditor. UltraCalendarCombo doesn't use any inbox controls, so EnableVisualStyles will not have any effect. It gives the user a slightly different (and IMO, better) experience when entering dates. There's no masking and it's more like MS Outlook. 

    The only caveat about this approach is that if you are using UltraGrids in your application and want a consistent experience, then you will need to set up your grid to use UltraCalendarCombo as the EditorComponent for any Date columns you might have.