This is a migrated thread and some comments may be shown as answers.

RadCalendar SpecialDayz Backcolor change

1 Answer 256 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
RONNY
Top achievements
Rank 1
RONNY asked on 16 May 2014, 08:54 AM
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

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 May 2014, 01:31 PM
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.
 
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
RONNY
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or