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

Hide day number on special days?

6 Answers 100 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Phillip Foster
Top achievements
Rank 1
Phillip Foster asked on 18 May 2011, 03:40 PM
I am aware of how to add special days, however, I would like to hide the text of the day on the calendar. 

So if my hostitem is a picture, the picture is displayed, but the day number is not. 

when the day number is displayed, it sometimes make the image confusing. 


Thanks!

6 Answers, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 23 May 2011, 09:34 PM
Hello Phillip Foster,

You can subscribe to the ElementRender event and set the DrawText property of the element being rendered to false if its date is among the special dates:

this.radCalendar1.ElementRender += new Telerik.WinControls.UI.RenderElementEventHandler(radCalendar1_ElementRender);
 
void radCalendar1_ElementRender(object sender, Telerik.WinControls.UI.RenderElementEventArgs e)
{
    if (this.radCalendar1.SpecialDays.Find(e.Day.Date).GetLength(0) > 0)
    {
        e.Element.DrawText = false;
    }
}

I hope this helps. If you have any additional questions, do not hesitate to ask.

Kind regards,
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.
0
Phillip Foster
Top achievements
Rank 1
answered on 25 May 2011, 07:35 PM
This works.... here's a modification to the question.

there are multiple "special day" types that I want to use.

Some of them should hide the number, some should not.

I can't seem to get access to a "tag" or any other field that would determine if this is a special day that I should hide.

any suggestions.

Thanks!!
0
Phillip Foster
Top achievements
Rank 1
answered on 27 May 2011, 03:44 PM
Actually....I made a workaround for this. BUT I have a couple of issues now.  (Code below)

1.)
when I create a special day (host item is an image) and make the "DrawText = false"
the day is not selectable... even when I set the day.Selectable = true;

2.)
In the ElementRender event, I set e.Element.BackColor for the weekends and DrawText = true;
this works initially... but on changing the month on the calendar and then changing back, the numbers no longer display. See attached screenies.

private void calAtt_ElementRender(object sender, RenderElementEventArgs e)
 {
      if (this.calAtt.SpecialDays.Find(e.Day.Date).GetLength(0) > 0)
      {
            if (!isShowNumber(e.Day.Date))
            {
                    e.Day.Selectable = true;
                    e.Element.DrawText = false;
            }
            else
                   e.Element.BackColor = getBackColor(e.Day.Date);
                 
       }
       else
       {
           e.Element.DrawText = true;
           e.Element.BackColor = Color.White;
       }
}


Thank you!!
0
Ivan Todorov
Telerik team
answered on 30 May 2011, 01:26 PM
Hi Phillip,

Despite my efforts, I was not able to reproduce these issues. They might be caused due to some logic in your isShowNumber and getBackColor methods which I am not aware of. Therefore, I would kindly ask you to send me a sample project that reproduces this issue. This will let me investigate this case in detail and provide you with appropriate answer.

Currently, I can notice that you are not resetting the DrawText property when a day is a special date and isShowNumber returns true, which can cause the second issue. Here is a code snippet that demonstrates how this should be addressed:
if (this.radCalendar1.SpecialDays.Find(e.Day.Date).GetLength(0) > 0)
{
    if (!isShowNumber(e.Day.Date) )
    {
        e.Day.Selectable = true;
        e.Element.DrawText = false;
    }
    else
    {
        e.Element.BackColor = getBackColor(e.Day.Date);
        e.Element.DrawText = true;
    }
}

Hope this helps.

I am looking forward to hearing from you.

Regards,
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.
0
Phillip Foster
Top achievements
Rank 1
answered on 06 Jun 2011, 02:57 PM
It seems to be more based around the fact that there is a image for the hostitem. the days that are just a different color, I can select. but the ones with an image cannot.

For #2, That change in the code worked great.
0
Ivan Todorov
Telerik team
answered on 09 Jun 2011, 09:14 AM
Hello Phillip Foster,

You were right that this is related to the PictureBox in the host item. In the .NET framework controls do not notify their parent about mouse events. In your case, the PictureBox handles the MouseDown event and the RadCalendar does not get notified for it, hence no cell is selected. I have managed to workaround this by subscribing to each PicutreBox's MouseDown event and setting the SelectedDate of the calendar explicitly. Here is a code snippet that demonstrates this:
for (int i = 0; i < this.radCalendar1.SpecialDays.Count; i++)
{
    PictureBox pictureBox = new PictureBox();
 
    pictureBox.Image = Image.FromFile(@"C:\image.png");
     
    RadHostItem hostitem = new RadHostItem(pictureBox);
     
    DateTime date = this.radCalendar1.SpecialDays[i].Date;
 
    hostitem.HostedControl.MouseDown += delegate(object sender, MouseEventArgs e)
    {
        this.radCalendar1.SelectedDate = date;
        this.radCalendar1.FocusedDate = date;
    };
 
    this.radCalendar1.SpecialDays[i].TemplateItem = hostitem;
}

I hope this is helpful. Do not hesitate to contact me if you have any additional questions.

Kind regards,
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.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Phillip Foster
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Phillip Foster
Top achievements
Rank 1
Share this question
or