Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Get Screen Bounds of DayContents (Read 6874 times)
tomk
YaBB Newbies
*
Offline


Yaos!

Posts: 29
Joined: Apr 25th, 2006
Get Screen Bounds of DayContents
Nov 20th, 2006 at 2:38pm
Print Post  
I need to track a subregion of individual Days in a Month or MonthRange view and respond to user interaction such as mouse events.
If we could call a method to retrieve DayContent element bounds in screen or client terms by index (DateTime would make sense), that would be great, or if there is a better way to make the cells "active" let us know.  It may also be helpful to get the location index (row x column) of the square in the Month(Range) grid.  I looked at the other posting about items and controls embedded which was very helpful, but this seems to apply only to Timetables.

Also, the Bounds passed in the Draw event args are incorrect for DayContents and we are unable to translate them to Client coordinates as is thus the request above.  For example, if the DayContents are in a 100x100 rectangle, the height will be 0 but the Y value will be 100. We have figured out that the Y is actually 0 relative to the day cell (contents) being drawn but the height should be 100, so we have a helper method translate the bounds.  Is this expected?

Thanks in advance yet again.  This control is great.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Get Screen Bounds of DayContents
Reply #1 - Nov 21st, 2006 at 6:05am
Print Post  
A new member DayCell will be added to the CalendarElement enumeration in the next release which will enable you to get the bounding rectangle of a day cell in client coordinates given its 0-based index.

As for the bounding rectangle passed as argument to the Draw event handler, here is an explanation that might be helpful. Each day cell contains a header and a contents part. The size of the header part is determined by the HeaderSize property of the DayRange object in the corresponding settings class. The rest of the day cell is considered contents. If however, the value of the HeaderSize property is 0, this indicates that the header of the cell will cover the entire cell leaving no space for contents. I believe thats the case with you and that why the bounding rectangle passed to the Draw event handler has 0 height and 100 Y-axis offset. Try drawing the header of the cell instead.

Meppy
  
Back to top
 
IP Logged
 
tomk
YaBB Newbies
*
Offline


Yaos!

Posts: 29
Joined: Apr 25th, 2006
Re: Get Screen Bounds of DayContents
Reply #2 - Nov 29th, 2006 at 5:57pm
Print Post  

Ok, thanks & let us when the new parameter for GetElementBounds is available for testing.

It sounds like we may need to ask you to add CalendarElement.DayHeader to the options for the control.  I tried setting Calendar.MonthSettings.DaySettings.HeaderSize to greater than 0 in a recent build which appeared to have DayContents option in GetElementBounds, but I always got an empty rectangle back for the contents.  In other words I tried to force it to use DayContents by setting the header as suggested but was unable to get the bounds (and the Contents still has 0 height).


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


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Get Screen Bounds of DayContents
Reply #3 - Dec 1st, 2006 at 7:22am
Print Post  
Try downloading this version:

https://mindfusion.org/_planner/_Planner.NET_41pre_trial14.zip
(This is a temporary link and is not guaranteed to work in the future.)

The new CustomDrawElement - DayContents should be available in it. The following code is working fine for me with DaySettings.HeaderSize = 20:

Code
Select All
if (e.Date == new DateTime(2006, 12, 1))
{
  if (e.Element == CustomDrawElements.DayHeader)
  {
    e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
    e.Graphics.DrawString("Header", Font, Brushes.White,
	new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
  }
  else if (e.Element == CustomDrawElements.DayContents)
  {
    e.Graphics.FillRectangle(Brushes.Blue, e.Bounds);
    e.Graphics.DrawString("Contents", Font, Brushes.White,
	new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
  }
} 



This is the contents of the Draw event handler with Calendar.CustomDraw set to DayHeader | DayContents.

Meppy
  
Back to top
 
IP Logged
 
tomk
YaBB Newbies
*
Offline


Yaos!

Posts: 29
Joined: Apr 25th, 2006
Re: Get Screen Bounds of DayContents
Reply #4 - Dec 4th, 2006 at 5:29pm
Print Post  
Meppy,

Sorry I should have written more clearly.  I was expecting that you would add CalendarElement.DayContents as an enumeration member on the element option of GetElementBounds.  So I was trying to say we might also need CalendarElement.DayHeader depending on if we use day headers or not.  However it looks like you've added the whole DayCell, which is great.  We can always split that ourselves into Header and Contents rectangles in client coordinates using the DayCell bounds plus the header height, if any.

I've tested the download and it looks like I'm not getting any bounds for cells other than the first (index==0).  I added some console writelines capturing draw on DayContents and DayHeader but I've never seen the other cells's bounds and always get the same location (x, y):

void calendar1_Draw(object sender, MindFusion.Scheduling.WinForms.CustomDrawArgs e)
       {
           Rectangle drawingBounds = Rectangle.Empty;
           switch (e.Element)
           {
               case MindFusion.Scheduling.WinForms.CustomDrawElements.DayHeader:
               case MindFusion.Scheduling.WinForms.CustomDrawElements.DayContents:
                   drawingBounds = calendar1.GetElementBounds(MindFusion.Scheduling.WinForms.CalendarElement.DayCel
l, e.Index);
                   break;
               default:
                   return;
           }

           if (drawingBounds != Rectangle.Empty)
           {
               Console.WriteLine(string.Format("Item index:{0}, bounds:{1}", e.Index.ToString(), drawingBounds.ToString()));
           }
       }
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Get Screen Bounds of DayContents
Reply #5 - Dec 5th, 2006 at 6:10am
Print Post  
CustomDrawItem.Index was initially designed to return the index only of a custom drawn view column or item. In all other cases, including DayCell the Index returns 0. This is the reason Calendar.GetElementBounds to always return the bounding rectangle of the first cell. It is logical, however, that Index also returns the index of a custom drawn day cell, so we have expanded its meaning to cover this case. I will send you a version that contains this through e-mail.

As a side not, it might be more convenient to use the CustomDrawArgs.Bounds property to obtain the bounding rectangle of the drawn element in the Calendar.Draw event handler instead of querying it explicitly through Calendar.GetElementBounds method.

Meppy
« Last Edit: Dec 5th, 2006 at 2:35pm by Meppy »  
Back to top
 
IP Logged
 
tomk
YaBB Newbies
*
Offline


Yaos!

Posts: 29
Joined: Apr 25th, 2006
Re: Get Screen Bounds of DayContents
Reply #6 - Dec 5th, 2006 at 2:28pm
Print Post  

What we are trying to do is update the screen outside of Paint (Draw) events, and add some other interactive features that use hit testing inside certain areas of the bounding rect.  This is why we need the client coordinates, so we can use the correct coordinates (or translate to screen to draw to device context) if needed.

I tried to use Invalidate(rectangle) with Update with the Control but the Draw events only seem to fire if you invalidate the whole control with its children Invalidate(true)...This may be because of confusion on my part about which coordinate system to use, or because I need to handle Invalidate instead of Draw - but if the latter I need to know the non-internal [e.g. client or screen] coordinates of the area, don't I?

Definitely inside a Draw event you only need the Bounds in the args to use that particular surface.  However for some situations (as mentioned above) we require different information.  For example one of the components we are using to change interaction is based on screen system.  For example, if you mouse over a certain part of the Day Cell this component changes state, and responds to events such as clicks.  Since we cannot imbed a control inside the cell "directly" we are trying to get the coordinates in more "absolute" screen or client terms in order to process these messages/events/et al.

How would you recommend we do this for days in a Month if not with GetElementBounds which I agree may not be the best candidate since it doesn't use an index which makes clear sense for Month view?  I was thinking a method to get DayCell by date index could be added, but I realize this might be something more difficult/time consuming for you guys to develop.  If there is already a better way I'm of course open to suggestion.
  
Back to top
 
IP Logged
 
Charliemouse
YaBB Newbies
*
Offline



Posts: 4
Joined: Dec 5th, 2006
Re: Get Screen Bounds of DayContents
Reply #7 - Dec 5th, 2006 at 2:49pm
Print Post  
I think I have a related problem - apologies if it isn't.

I am replicating the Drag'n'Drop example provided in the distribution, but using a Timetable view and GroupByLocations.

The drop functionality works fine, but when implementing Draw, I cannot establish which Location/column the current cell is in, so I cannot draw the 'drag over' box correctly.  The e.Bounds has identical coordinates for every cell on a given row.

Please help.

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


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Get Screen Bounds of DayContents
Reply #8 - Dec 6th, 2006 at 7:19am
Print Post  
Hi Charliemouse,

The Graphics property of the CustomDrawArgs class has been pretranslated before the event handler is invoked. That's why the Bounds property looks identical for each cell. Drawing within this bounds using the supplied graphics will paint exactly within the appropriate cell.

In order to check which location the current cell is in within the Calendar.Draw event handler, you have to inspect the Resource property of the event args object. It contains a reference to the related Location, Resource, Task or Contact (depending on the current GroupType).

If you make an application similar to the Drag & Drop sample, there is a place in the DragOver event handler, where the date under the cursor is obtained (in order to be subsequently custom-painted) through a call to the Calendar.GetDateAt method. If you are using a groupped view, however, you may also have to obtain a reference to the resource associated with the pointed date, by calling Calendar.GetResource method.

I hope this helps.

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


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Get Screen Bounds of DayContents
Reply #9 - Dec 6th, 2006 at 7:46am
Print Post  
As for the Calendar.GetElementBounds method, it indeed uses an index in order to identify the element whose bounding rectangle is required. It is not always trivial however, to calculate the 0-based index of a date whithin the view. In particular, the index of the cell in a SingleMonth view is not always the day within the month of the specified date. For example, if there are leading days from the previous month they use up indices as well.

Meppy
  
Back to top
 
IP Logged
 
Charliemouse
YaBB Newbies
*
Offline



Posts: 4
Joined: Dec 5th, 2006
Re: Get Screen Bounds of DayContents
Reply #10 - Dec 6th, 2006 at 8:04am
Print Post  
Thanks Meppy.

I know I checked the resource value and it was returning null, but now I try it again it works fine - must have been dreaming. Undecided
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Get Screen Bounds of DayContents
Reply #11 - Dec 6th, 2006 at 9:03am
Print Post  
The Resource might be null for elements that are not related to a resource (e.g. the timeline in the Timetable view) or if you have incidentally turned off grouping for some reason.

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