问题描述:Spread有很多内置快捷键行为,如何自定义快捷键对应的行为。
问题解答:可以通过继承 Action 类,重载其PerformAction方法自定义键盘行为。
关键代码:
- 自定义SpreadAction
- ///<summary>
- ///默认情况下 Ctrl + Home 即选择Cell[0,0],自定义动作实现选择 Cell[0,1]
- ///</summary>
- public classNewControlHomeAction : FarPoint.Win.Spread.Action
- {
- public overridevoid PerformAction(object source)
- {
- if (source isSpreadView)
- {
- SpreadView SpreadView = (SpreadView)source;
- SpreadView.Sheets[SpreadView.ActiveSheetIndex].SetActiveCell(0, 1);
- SpreadView.ShowActiveCell(VerticalPosition.Top, HorizontalPosition.Left);
- }
- }
- }
复制代码
?
添加自定义SpreadAction,并且设置给Ctrl+Home快捷键
- fpSpread1.ActiveSheet.Columns[0].CanFocus = false;
- InputMap im = fpSpread1.GetInputMap(InputMapMode.WhenFocused);
- ActionMap am = fpSpread1.GetActionMap();
- im.Put(newKeystroke(Keys.Home, Keys.Control), "NewControlHomeAction");
- am.Put("NewControlHomeAction", newNewControlHomeAction());
复制代码
示例下载:点击下载 |
|