Hide day number on special days?

7 posts, 0 answers
  1. Phillip Foster
    Phillip Foster avatar
    58 posts
    Member since:
    Apr 2010

    Posted 18 May 2011 Link to this post

    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!
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 23 May 2011 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Phillip Foster
    Phillip Foster avatar
    58 posts
    Member since:
    Apr 2010

    Posted 25 May 2011 Link to this post

    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!!
  5. Phillip Foster
    Phillip Foster avatar
    58 posts
    Member since:
    Apr 2010

    Posted 27 May 2011 Link to this post

    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!!
  6. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 30 May 2011 Link to this post

    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.
  7. Phillip Foster
    Phillip Foster avatar
    58 posts
    Member since:
    Apr 2010

    Posted 06 Jun 2011 Link to this post

    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.
  8. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 09 Jun 2011 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready