private void Form1_Load(object sender, System.EventArgs e)
{
fpSpread1.EditModePermanent = true;
// 定义一个ENTER事件
FarPoint.Win.Spread.InputMap inputmap1;
inputmap1 = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
inputmap1.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.None);
}
private void fpSpread1_EditModeOn(object sender, System.EventArgs e)
{
//
fpSpread1.EditingControl.KeyDown += new System.Windows.Forms.KeyEventHandler(this.fpSpread1_KeyDown);
}
private void fpSpread1_EditModeOff(object sender, System.EventArgs e)
{
//
fpSpread1.EditingControl.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.fpSpread1_KeyDown);
}
private void fpSpread1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Console.WriteLine("ENTER.KEYDOWN");
}
}
以下是VB.NET
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
FpSpread1.EditModePermanent = True
Dim im As New FarPoint.Win.Spread.InputMap
im = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused)
im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.None)
End Sub
Private Sub FpSpread1_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOn
''进入编辑状态
Dim KeyDownHandler As KeyEventHandler = AddressOf FpSpread1_KeyDown
AddHandler FpSpread1.EditingControl.KeyDown, KeyDownHandler
End Sub
Private Sub FpSpread1_EditModeOff(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOff
''解除编辑状态
Dim KeyDownHandler As KeyEventHandler = AddressOf FpSpread1_KeyDown
RemoveHandler FpSpread1.EditingControl.KeyDown, KeyDownHandler
End Sub
Private Sub FpSpread1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles FpSpread1.KeyDown
If e.KeyCode = Keys.Enter Then
Debug.WriteLine("Enter.KeyDown")
End If
End Sub
方法3:
private void fpSpread1_EditModeOn(object sender, System.EventArgs e)
{
//Handle respective Key events at the timing when cell editing begins.
fpSpread1.EditingControl.KeyDown += new KeyEventHandler(this.fpSpread1_KeyDown);
fpSpread1.EditingControl.KeyPress += new KeyPressEventHandler(this.fpSpread1_KeyPress);
fpSpread1.EditingControl.KeyUp += new KeyEventHandler(this.fpSpread1_KeyUp);
}
private void fpSpread1_EditModeOff(object sender, System.EventArgs e)
{
//Release respective Key event handles at the timing when cell editing is complete.
fpSpread1.EditingControl.KeyDown -= new KeyEventHandler(this.fpSpread1_KeyDown);
fpSpread1.EditingControl.KeyPress -= new KeyPressEventHandler(this.fpSpread1_KeyPress);
fpSpread1.EditingControl.KeyUp -= new KeyEventHandler(this.fpSpread1_KeyUp);
}
private void fpSpread1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
Console.WriteLine("KeyDown event: " + e.KeyCode.ToString());
}
private void fpSpread1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
Console.WriteLine("KeyPress event: " + e.KeyChar.ToString());
}
private void fpSpread1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
Console.WriteLine("KeyUp event: " + e.KeyCode.ToString());
}
Visual Basic .NET Code
Private Sub FpSpread1_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOn
'Handle respective Key events at the timing when cell editing begins.
Dim KeyDownHandler As KeyEventHandler = AddressOf FpSpread1_KeyDown
AddHandler FpSpread1.EditingControl.KeyDown, KeyDownHandler
Dim KeyPressHandler As KeyPressEventHandler = AddressOf FpSpread1_KeyPress
AddHandler FpSpread1.EditingControl.KeyPress, KeyPressHandler
Dim KeyUpHandler As KeyEventHandler = AddressOf FpSpread1_KeyUp
AddHandler FpSpread1.EditingControl.KeyUp, KeyUpHandler
End Sub
Private Sub FpSpread1_EditModeOff(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.EditModeOff
'Release respective Key event handles at the timing when cell editing is complete.
Dim KeyDownHandler As KeyEventHandler = AddressOf FpSpread1_KeyDown
RemoveHandler FpSpread1.EditingControl.KeyDown, KeyDownHandler
Dim KeyPressHandler As KeyPressEventHandler = AddressOf FpSpread1_KeyPress
RemoveHandler FpSpread1.EditingControl.KeyPress, KeyPressHandler
Dim KeyUpHandler As KeyEventHandler = AddressOf FpSpread1_KeyUp
RemoveHandler FpSpread1.EditingControl.KeyUp, KeyUpHandler
End Sub
Private Sub FpSpread1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles FpSpread1.KeyDown
Console.WriteLine("KeyDown event: " + e.KeyCode.ToString)
End Sub
Private Sub FpSpread1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles FpSpread1.KeyPress
Console.WriteLine("KeyPress event: " + e.KeyChar.ToString)
End Sub
Private Sub FpSpread1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles FpSpread1.KeyUp
Console.WriteLine("KeyUp event: " + e.KeyCode.ToString)
End Sub