protected override void OnMouseDown(MouseEventArgs e) { TimeFrameObject tfo = GetTimeFrameObject(e); if (tfo != null) { if (e.Button == MouseButtons.Left) { tfo.Selected = !tfo.Selected; tfoLastSelected = tfo; this.Invalidate(true); } } }
private TimeFrameObject GetTimeFrameObject(MouseEventArgs e) { TimeFrameObject tfo = null; if (Grid.Contains(e.X, e.Y)) { tfo = CellMatrix[(int)((e.Y - Header) / y_grid_inc), (int)((e.X - LeftMargin) / x_grid_inc)]; } else if ((e.X > Grid.X) && (e.X < (Grid.X + Grid.Width)) && (e.Y < Grid.Y)) { tfo = (TimeFrameObject)TimeSlots[(int)((e.X - LeftMargin) / x_grid_inc)]; } else if ((e.X < Grid.X) && (e.Y < (Grid.Y + Grid.Height)) && (e.Y > Grid.Y)) { tfo = (_Day)Days[(int)((e.Y - Header) / y_grid_inc)]; } else if (TopLeft.Contains(e.X, e.Y)) { tfo = TopLeft; } return(tfo); }
protected override void OnMouseMove(MouseEventArgs e) { ClearToolTopState(); TimeFrameObject tfo = GetTimeFrameObject(e); if (e.Button == MouseButtons.Left) { if (tfo is Cell) { Cell cellNewSelected = (Cell)tfo; if (tfoLastSelected is Cell) { Cell cellLastSelected = (Cell)tfoLastSelected; if (cellLastSelected != cellNewSelected) { SelectCellBlock(cellLastSelected, cellNewSelected); } } } else if (tfo is TimeSlot) { TimeSlot tsNewSelected = (TimeSlot)tfo; if (tfoLastSelected is TimeSlot) { TimeSlot tsLastSelected = (TimeSlot)tfoLastSelected; if (tsLastSelected != tsNewSelected) { if (tsNewSelected.Column > tsLastSelected.Column) { for (int j = tsLastSelected.Column; j < tsNewSelected.Column; ++j) { TimeSlots[j].Selected = tsLastSelected.Selected; } } else if (tsNewSelected.Column < tsLastSelected.Column) { for (int j = tsNewSelected.Column; j < tsLastSelected.Column; ++j) { TimeSlots[j].Selected = tsLastSelected.Selected; } } } } } else if (tfo is _Day) { _Day dNewSelected = (_Day)tfo; if (tfoLastSelected is _Day) { _Day dLastSelected = (_Day)tfoLastSelected; if (dLastSelected != dNewSelected) { if (dNewSelected.Row > dLastSelected.Row) { for (int i = dLastSelected.Row; i < dNewSelected.Row; ++i) { Days[i].Selected = dLastSelected.Selected; } } else if (dNewSelected.Row < dLastSelected.Row) { for (int i = dNewSelected.Row; i < dLastSelected.Row; ++i) { Days[i].Selected = dLastSelected.Selected; } } } } } } if (tfoLastHighlighted != null) { tfoLastHighlighted.Highlighted = false; } if (tfo != null) { tfo.Highlighted = true; tfoLastHighlighted = tfo; } if (e.Button == MouseButtons.None) { if (Grid.Contains(e.X, e.Y)) { LastMouseHover = e; HoverTimerStart.Start(); } } this.Invalidate(true); }