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