Style Certain Dates

2 posts, 0 answers
  1. Robert
    Robert avatar
    23 posts
    Member since:
    Feb 2009

    Posted 26 May 2011 Link to this post

    I'm using Q1 2011.

    I simply want to change the style of a specific set of dates that are determined at runtime.

    I'm overriding the ElementRender event and setting properties like e.Element.Font, e.Element.ForeColor, etc. This works great. For instance:

    private void calSchedule_ElementRender(object sender, RenderElementEventArgs e)
    {
        if(myDates.Contains(e.Day.Date))
        {
            e.Element.Font = new Font(e.Element.Font.FontFamily, 9f, FontStyle.Bold);
            e.Element.ForeColor = Color.Green;
            e.Element.AutoToolTip = true;
        }
    }


    The problem is, from that point on, the cell will continue to render those styles even if the date inside that cell changes. (Like when the calender's month is change.)

    Since the "correct" style for the cell can vary, I can't simply reset the values manually. How can I resolve this?
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 28 May 2011 Link to this post

    Hello Robert,

    Thank you for your question.

    In RadCalendar the visual elements are reused when possible and that is why when you create a local property setting, it remains when the date in cell has changed. You can reset the properties which are RadProperties by using the ResetValue method which will set a RadProperty with its default or theme value:
    private void calSchedule_ElementRender(object sender, RenderElementEventArgs e)
    {
        if(myDates.Contains(e.Day.Date))
        {
            e.Element.Font = new Font(e.Element.Font.FontFamily, 9f, FontStyle.Bold);
            e.Element.ForeColor = Color.Green;
            e.Element.AutoToolTip = true;
        }
        else
        {
             e.Element.ResetValue(VisualElement.FontProperty);
             e.Element.ResetValue(VisualElement.ForeColorProperty);
             e.Element.AutoToolTip = false;
        }
    }

    I hope this will help you. Feel free to ask if you have any additional questions.

    Greetings,
    Ivan Todorov
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top