private void OnCanvasEvent(object obj, CanvasEventArgs args)
 {
     EventButton ev = new EventButton (args.Event.Handle);
     switch (ev.Type)
     {
         case EventType.ButtonPress:
             if (ev.Button == 1)
             {
                 holding= true;
                 firstCell = taskArea.GetCellAt (ev.X, ev.Y);
                 StartDrawing (ev);
             }
             break;
         case EventType.MotionNotify:
             if (holding && stask != null)
             {
                 curCell = taskArea.GetCellAt (ev.X, ev.Y);
                 stask.Y2 = ev.Y;
             }
             break;
         case EventType.ButtonRelease:
             holding = false;
             double rounded = RoundDownTask (ev.Y);
             stask.Y2 = rounded;
             PointToTime (firstCell, curCell, stask.Task, firstX, firstY, ev.X, rounded);
             break;
         default:
             break;
     }
 }
 private void PointToTime(Cell firstCell, Cell curCell, Task task, double firstX, double firstY, double curX, double curY)
 {
     task.EndingHour = curCell.Row + 8;
     task.EndingMinute = (int) ((curY - (curCell.Row * curCell.Height)) / PlannerWindow.minuteLength);
 }
 private double RoundMinutes(Cell cell, double y)
 {
     double minutes = y - (cell.Row * cell.Height);
     double roundup = 0;
     if ((minutes - cell.Height/2) < 0)
     {
         if ((minutes - cell.Height/4) < 0)
             roundup = 0;
         else
             roundup = cell.Height/4;
     } else {
         if ((minutes - ((cell.Height/4) * 3)) < 0)
             roundup = cell.Height/2;
         else
             roundup = (cell.Height/4) * 3;
     }
     return y - minutes + roundup;
 }