public override bool OnMouseMove(Point location, MouseButtons buttons) { bool isProcessed = false; switch (sheet.operationStatus) { case OperationStatus.AdjustColumnWidth: if (sheet.currentColWidthChanging >= 0 && buttons == MouseButtons.Left) { ColumnHeader colHeader = sheet.cols[sheet.currentColWidthChanging]; sheet.headerAdjustNewValue = location.X - colHeader.Left; if (sheet.headerAdjustNewValue < 0) { sheet.headerAdjustNewValue = 0; } this.sheet.controlAdapter.ChangeCursor(CursorStyle.ChangeColumnWidth); this.sheet.RequestInvalidate(); isProcessed = true; } break; case OperationStatus.Default: { if (sheet.currentColWidthChanging == -1 && sheet.currentRowHeightChanging == -1) { int col = -1; // find the column index bool inline = sheet.FindColumnByPosition(location.X, out col) && sheet.HasSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth); if (col >= 0) { CursorStyle curStyle = inline ? CursorStyle.ChangeColumnWidth : (sheet.selectionMode == WorksheetSelectionMode.None ? CursorStyle.Selection : CursorStyle.FullColumnSelect); var header = sheet.cols[col]; // check if header body exists if (header.Body != null) { // let cell's body decide the mouse behavior var arg = new WorksheetMouseEventArgs(sheet, new Point( ((location.X - header.Left) * this.scaleFactor), (location.Y / this.scaleFactor)), location, buttons, 1) { CursorStyle = curStyle }; isProcessed = header.Body.OnMouseMove( new Size(header.InnerWidth * this.scaleFactor, sheet.colHeaderHeight), arg); curStyle = arg.CursorStyle; } sheet.controlAdapter.ChangeCursor(curStyle); } } } break; case OperationStatus.FullColumnSelect: case OperationStatus.FullSingleColumnSelect: if (buttons == MouseButtons.Left) { sheet.controlAdapter.ChangeCursor(CursorStyle.FullColumnSelect); sheet.SelectRangeEndByMouse(this.PointToController(location)); isProcessed = true; } break; } return(isProcessed); }
/// <summary> /// Method raised when mouse moving inside this body. /// </summary> /// <param name="headerSize">Header size</param> /// <param name="e">Event argument</param> /// <returns>true if this event is handled</returns> public virtual bool OnMouseMove(Size headerSize, WorksheetMouseEventArgs e) { return(false); }
public override bool OnMouseDown(Point location, MouseButtons buttons) { bool isProcessed = false; switch (sheet.operationStatus) { case OperationStatus.Default: int col = -1; bool inSeparator = sheet.FindColumnByPosition(location.X, out col); if (col >= 0) { // adjust columns width if (inSeparator && buttons == MouseButtons.Left && sheet.HasSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth)) { sheet.currentColWidthChanging = col; sheet.operationStatus = OperationStatus.AdjustColumnWidth; sheet.controlAdapter.ChangeCursor(CursorStyle.ChangeColumnWidth); sheet.RequestInvalidate(); this.headerAdjustBackup = sheet.headerAdjustNewValue = sheet.cols[sheet.currentColWidthChanging].InnerWidth; this.SetFocus(); isProcessed = true; } if (!isProcessed) { var header = sheet.cols[col]; if (header.Body != null) { // let body to decide the mouse behavior var arg = new WorksheetMouseEventArgs(sheet, new Point( ((location.X - header.Left) * this.scaleFactor), (location.Y / this.scaleFactor)), new Point((location.X - header.Left) * this.scaleFactor + this.Left, location.Y / this.scaleFactor), buttons, 1); isProcessed = header.Body.OnMouseDown( new Size(header.InnerWidth * this.scaleFactor, sheet.colHeaderHeight), arg); } } if (!isProcessed // do not allow to select column if selection mode is null && sheet.selectionMode != WorksheetSelectionMode.None) { bool isFullColSelected = (sheet.selectionMode == WorksheetSelectionMode.Range && sheet.selectionRange.Rows == sheet.rows.Count && sheet.selectionRange.ContainsColumn(col)); // select whole column if ((!isFullColSelected || buttons == MouseButtons.Left)) { sheet.operationStatus = OperationStatus.FullColumnSelect; sheet.controlAdapter.ChangeCursor(CursorStyle.FullColumnSelect); SetFocus(); sheet.SelectRangeStartByMouse(this.PointToController(location)); isProcessed = true; } } // show context menu if (buttons == MouseButtons.Right) { sheet.ControlAdapter.ShowContextMenuStrip(ViewTypes.ColumnHeader, this.PointToController(location)); } } break; } return(isProcessed); }