请参考如下示例代码实现之:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ButtonCellType buttonCell = new ButtonCellType();
this.fpSpread1.ActiveSheet.Columns[1].CellType = buttonCell;
this.fpSpread1.ButtonClicked += fpSpread1_ButtonClicked;
InputMap im = fpSpread1.GetInputMap(InputMapMode.WhenFocused);
ActionMap am = fpSpread1.GetActionMap();
im.Put(new Keystroke(Keys.Enter, Keys.None), "ClickButtonAction");
am.Put("ClickButtonAction", new ClickButtonAction());
}
public static void fpSpread1_ButtonClicked(object sender, EditorNotifyEventArgs e)
{
MessageBox.Show("Button Click test!");
}
private class ClickButtonAction : FarPoint.Win.Spread.Action
{
public override void PerformAction(object source)
{
if (source is SpreadView)
{
SpreadView spreadView = (SpreadView)source;
Form1.fpSpread1_ButtonClicked(spreadView, null);
}
}
}
} |