在 SelectionChanging 中判断当前的鼠标行为,大概实现思路如下:
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- // 鼠标左键是否按下
- bool Draging = false;
- // 鼠标是否处于左键按下的移动过程中
- bool Moving = false;
- private void Form1_Load(object sender, EventArgs e)
- {
- fpSpread1.MouseDown += new MouseEventHandler(fpSpread1_MouseDown);
- fpSpread1.MouseMove += new MouseEventHandler(fpSpread1_MouseMove);
- fpSpread1.MouseUp += new MouseEventHandler(fpSpread1_MouseUp);
- fpSpread1.SelectionChanging += new FarPoint.Win.Spread.SelectionChangingEventHandler(fpSpread1_SelectionChanging);
- }
- private void fpSpread1_MouseMove(object sender, MouseEventArgs e)
- {
- if (Draging)
- {
- // 鼠标处于按下左键的移动过程中
- Moving = true;
- }
- }
- private void fpSpread1_SelectionChanging(object sender, FarPoint.Win.Spread.SelectionChangingEventArgs e)
- {
- if (Draging && Moving)
- {
- // 取消鼠标移动所引起的选中区域变化
- e.Cancel = true;
- return;
- }
- }
-
- private void fpSpread1_MouseDown(object sender, MouseEventArgs e)
- {
- Draging = true;
- }
- private void fpSpread1_MouseUp(object sender, MouseEventArgs e)
- {
- Draging = false;
- Moving = false;
- }
- }
复制代码 |