Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic CalendarElement on GetElementBounds() signature (Read 2909 times)
fer mayorga
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Oct 17th, 2006
CalendarElement on GetElementBounds() signature
Dec 19th, 2006 at 7:43pm
Print Post  
We use the OwnerDraw event to apply style to CalendarElements (daycells). We set our own styles by drawing our own brushes and rectangles.

The problem is that when the day is selected is not visual because of our custom drawing on top.  For this we would like to set the a custom "selected style" by drawing again.

I am trying to use the monthControl.GetElementBounds(CalendarElement calendarElement, int index) method to get the bounds.

I only have the selected date.  Where do I get the CalendarElement and the Index from?

I hope my explanation was clear...
thanks in advanced.

Fernando Mayorga
TBS
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: CalendarElement on GetElementBounds() signatur
Reply #1 - Dec 20th, 2006 at 6:16am
Print Post  
The following code illustrates how to perform custom drawing on a day cell, taking into consideration whether this cell is selected or not.

Code
Select All
private void calendar_Draw(object sender, MindFusion.Scheduling.WinForms.CustomDrawArgs e)
{
	if (e.Date == new DateTime(2006, 12, 24) ||
		e.Date == new DateTime(2006, 12, 25))
	{
		if (e.Element == CustomDrawElements.DayHeader)
		{
			if (calendar1.Selection.Contains(e.Date))
				e.Graphics.FillRectangle(Brushes.Yellow, e.Bounds);
			else
				e.Graphics.FillRectangle(Brushes.LightSteelBlue, e.Bounds);

			RectangleF bounds = new RectangleF(
				e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
			Brush brush = new SolidBrush(e.Style.HeaderTextColor);
			Font f = e.Style.HeaderFont;
			if (f == null)
				f = Font;

			StringFormat format = new StringFormat();
			// We should check e.Style.HeaderTextAlignment,
			// but use centered for simplicity
			format.Alignment = StringAlignment.Center;
			format.LineAlignment = StringAlignment.Center;

			e.Graphics.DrawString(e.Date.Day.ToString(),
				f, brush, bounds, format);

			format.Dispose();
			brush.Dispose();
		}
		else if (e.Element == CustomDrawElements.DayContents)
		{
			if (calendar1.Selection.Contains(e.Date))
				e.Graphics.FillRectangle(Brushes.DarkGoldenrod, e.Bounds);
			else
				e.Graphics.FillRectangle(Brushes.SteelBlue, e.Bounds);
		}
	}
} 



The code draws the dates 24th and 25th of December, so make sure thay are visible within your view.

Meppy
  
Back to top
 
IP Logged
 
fer mayorga
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Oct 17th, 2006
Re: CalendarElement on GetElementBounds() signatur
Reply #2 - Jan 2nd, 2007 at 1:42pm
Print Post  
Happy new year Meppy!
thanks for the reply.

We are already implementing the code you are suggesting, but that is using the Draw event.
I would like to custom draw on the selection changed event. More like a custom selected style per day cell.

Since we have custom drawing in each cell already I would like to preserve the that style (custom drawn) plus adding a selected style indicator. I was trying to use the:

_monthControl.GetElementBounds(CalendarElement, index)

method to get the bounds of the selected element and draw on it.

Please let me know if there is another way of doing this more efficiently.

Greatly appreciated,

Fernando Mayorga
TBS

  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: CalendarElement on GetElementBounds() signatur
Reply #3 - Jan 3rd, 2007 at 7:29am
Print Post  
It is best to do all custom drawing in one place to avoid losing consistency. If you need custom style for specific dates and additional visual indication for selected dates, then I would recommend handling both in the Draw event handler. It requires more efforts but gives you more control.

Meppy
  
Back to top
 
IP Logged
 
fer mayorga
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Oct 17th, 2006
Re: CalendarElement on GetElementBounds() signatur
Reply #4 - Jan 3rd, 2007 at 2:41pm
Print Post  
Thanks a lot for your help Meppy, your example and using the draw event solve my issues.

Thanks for the quick response!!!

Fernando
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint