protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (itemOnState != null) { itemOnState.SetIsResizingEndDate(false); itemOnState.SetIsResizingStartDate(false); planner.OnItemClick(new WeekPlannerItemEventArgs(itemOnState)); if (itemOnStateChanged) { planner.OnItemDatesChanged(new WeekPlannerItemEventArgs(itemOnState)); } itemOnState = null; } SetState(PlannerState.Idle); }
protected override void OnMouseDown(MouseEventArgs e) { mouseClickPosition = new Point(e.X, e.Y); mouseClickScrollPosition = mouseClickPosition - new Size(AutoScrollPosition); if (!Focused) { Focus(); } var row = RowCoord.Where(d => (isNumberInRange(mouseClickScrollPosition.Y, d.FirstCoord, d.SecondCoord))).SingleOrDefault(); _selectedRow = row != null ? row.RowIndex : -1; var column = ColumnCoord.Where(d => (isNumberInRange(mouseClickScrollPosition.X, d.FirstCoord, d.SecondCoord))).SingleOrDefault(); if (column != null) { _selectedColumn = column.Column; _selectedCellDate = CurrentDate.AddDays(SelectedColumn); } if (listRows.Count > 0 && _selectedRow != -1) { var plannerRow = listRows.ElementAt(_selectedRow); _selectedItem = GetItemAt(mouseClickScrollPosition, plannerRow.Items); } switch (State) { case PlannerState.Idle: if (_selectedItem != null) { itemOnState = _selectedItem; itemOnStateChanged = false; durationStart = itemOnState.StartDate.Date.Subtract(column.DateValue.Date); durationEnd = itemOnState.EndDate.Date.Subtract(column.DateValue.Date); if (itemOnState.ResizeStartDateZone(mouseClickScrollPosition)) { SetState(PlannerState.ResizingItem); itemOnState.SetIsResizingStartDate(true); } else if (itemOnState.ResizeEndDateZone(mouseClickScrollPosition)) { SetState(PlannerState.ResizingItem); itemOnState.SetIsResizingEndDate(true); } else { rowNumer = _selectedRow; SetState(PlannerState.DraggingItem); } } break; case PlannerState.DraggingItem: break; case PlannerState.ResizingItem: break; case PlannerState.EditingItemText: break; } if (row != null && column != null && listRows.Count > 0) { var rowClicked = listRows.ElementAt(_selectedRow); planner.OnRowClick(new RowEventArgs(rowClicked)); Invalidate(); } if (mouseClickScrollPosition.X < LeftMargin) { try { var rowClicked = listRows.ElementAt(_selectedRow); if (e.Button == MouseButtons.Left) { rowClicked.IsExpanded = !rowClicked.IsExpanded; } planner.OnRowLeftColumnClick(new RowClickEventArgs(rowClicked, e.Button), listRows.IndexOf(rowClicked)); rowClicked.LeftMarginBackColor = rowClicked.LeftMarginOldBackColor; } catch (System.ArgumentOutOfRangeException) { Debug.WriteLine("It happened"); } } base.OnMouseDown(e); }