RadCalendar SpecialDayz Backcolor change

2 posts, 0 answers
  1. RONNY
    RONNY avatar
    7 posts
    Member since:
    Nov 2011

    Posted 16 May 2014 Link to this post

    Hello,

    how can i change the Backcolor at SpecialDays?
    I read a xml file and create specialdays about this information automatically.
    When i create the specialdays with the following code, then i can not see the Day-Number.

    public void date_eintrag(string tick_imput, string text, int color)
             {            
                 long tick = Convert.ToInt64(tick_imput);
                 DateTime time = new DateTime(tick);
                 Telerik.WinControls.UI.RadCalendarDay day = new Telerik.WinControls.UI.RadCalendarDay();
                 Telerik.WinControls.RadHostItem item = new Telerik.WinControls.RadHostItem(new System.Windows.Forms.Control());
                 item.BackColor = Color.Transparent;
                 item.ForeColor = Color.Black;
                 item.Text = time.Day.ToString();
                 day.Date = time;
                 day.TemplateItem = item;
                 radCalendar1.SpecialDays.Add(day);
             }



    How is the right way for this function?



    Thanks in advance,


    Ronny Gleicke
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 16 May 2014 Link to this post

    Hi Ronny,

    Thank you for writing.

    Here is how to add a RadCalendarDay and change its BackColor:
    public Form1()
    {
        InitializeComponent();
     
        DateTime time = DateTime.Now.AddDays(2);
        Telerik.WinControls.UI.RadCalendarDay day = new Telerik.WinControls.UI.RadCalendarDay(time);
        radCalendar1.SpecialDays.Add(day);
        radCalendar1.ElementRender += radCalendar1_ElementRender;
    }
     
    void radCalendar1_ElementRender(object sender, RenderElementEventArgs e)
    {
        if (radCalendar1.SpecialDays.Contains(e.Day, new MyComparer()))
        {
            e.Element.BackColor = Color.Red;
        }
        else
        {
            e.Element.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }
     
    class MyComparer : IEqualityComparer<RadCalendarDay>
    {
        public bool Equals(RadCalendarDay day1, RadCalendarDay day2)
        {
            if (DateTime.Compare(day1.Date.Date, day2.Date.Date) == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
     
        public int GetHashCode(RadCalendarDay day)
        {
            return day.GetHashCode();
        }
    }

    Let me know how this works for you.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top