这是我写的 在CellClick事件里面写的 可以结贴了
private void fpSpread_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
{
// Cell cell = fpSpread.ActiveSheet.Cells[e.Row, e.Column];
if (e.Button == MouseButtons.Right)
{//当点击右键时判断当前格子是否在选中区域内
int l1, h1, l2, h2;
//选定区域
CellRange[] cells = fpSpread.ActiveSheet.GetSelections();
foreach (CellRange cell in cells)
{
h1 = cell.Row;
l1 = cell.Column;
h2 = cell.Row + cell.RowCount - 1;
l2 = cell.Column + cell.ColumnCount - 1;
if (!(e.Row >= h1 && e.Row <= h2 && e.Column >= l1 && e.Column <= l2))
{//如果当前格子不在选择区域内
fpSpread.ActiveSheet.ClearSelection();
fpSpread.ActiveSheet.AddSelection(e.Row, e.Column, 1, 1);
break;
}
}
}
} |