你可以通过下面代码实现该功能:
- private Int32 MaxLength = 10;
- private void fpSpread1_EditModeOn(object sender, EventArgs e)
- {
- FarPoint.Win.Spread.CellType.GeneralEditor editor = fpSpread1.EditingControl as FarPoint.Win.Spread.CellType.GeneralEditor;
- editor.KeyPress -= new KeyPressEventHandler(editor_KeyPress);
- editor.KeyPress += new KeyPressEventHandler(editor_KeyPress);
- }
- void editor_KeyPress(object sender, KeyPressEventArgs e)
- {
- string text = fpSpread1.ActiveSheet.ActiveCell.Text + e.KeyChar;
- if (text.Length > MaxLength)
- {
- e.Handled = true;
- }
- }
复制代码 |