回复 12楼babyface的帖子
Hello babyface,
请使用以下代码测试:
- private void Form2_Load(object sender, EventArgs e)
- {
- FarPoint.Win.Spread.CellType.TextCellType t = new FarPoint.Win.Spread.CellType.TextCellType();
- FarPoint.Win.Spread.InputMap ancestorOfFocusedMap = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
- FarPoint.Win.Spread.ActionMap am = fpSpread1.GetActionMap();
- am.Put("AltEnter", new myAction());
- ancestorOfFocusedMap.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), "AltEnter");
- ancestorOfFocusedMap.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), "AltEnter");
- fpSpread1.SetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused, ancestorOfFocusedMap);
- t.Multiline = true;
- fpSpread1.Sheets[0].Cells[1, 1].CellType = t;
- fpSpread1.Sheets[0].Rows[1].Height = 60;
- fpSpread1.Sheets[0].Columns[1].Width = 140;
- this.fpSpread1.EditModeOn += new EventHandler(fpSpread1_EditModeOn);
- }
- void fpSpread1_EditModeOn(object sender, EventArgs e)
- {
- FarPoint.Win.Spread.CellType.GeneralEditor myText = (FarPoint.Win.Spread.CellType.GeneralEditor)fpSpread1.EditingControl;
- myText.AcceptsReturn = false;
- }
- }
- public class myAction : FarPoint.Win.Spread.Action
- {
- public override void PerformAction(object sender)
- {
- FarPoint.Win.Spread.SpreadView ss = (FarPoint.Win.Spread.SpreadView)sender;
- FarPoint.Win.Spread.CellType.GeneralEditor editor = (FarPoint.Win.Spread.CellType.GeneralEditor)ss.EditingControl;
- string text = editor.Text;
- int start = editor.SelectionStart + 1;
- text = text.Substring(0, editor.SelectionStart) + "\n" + text.Substring(editor.SelectionStart, editor.Text.Length - editor.SelectionStart);
- ss.Sheets[0].SetValue(ss.Sheets[0].ActiveRowIndex, ss.Sheets[0].ActiveColumnIndex, text);
- ss.EditMode = true;
- editor = (FarPoint.Win.Spread.CellType.GeneralEditor)ss.EditingControl;
- editor.SelectionStart = start;
- }
- }
复制代码 |