回复 1楼miyaminn的帖子
抱歉让你久等了,关于自定义单元格类型的例子,请你先参考:
- class myCkBox : FarPoint.Win.Spread.CellType.CheckBoxCellType
- {
- CheckBox ckbx = new CheckBox();
- public myCkBox()
- {
- }
- new event EventHandler EditingCanceled;
- new event EventHandler EditingStopped;
- public override void StartEditing(EventArgs e, bool selectAll, bool autoClipboard)
- {
- return;
- }
- public override void CancelEditing()
- {
- EditingCanceled(ckbx, EventArgs.Empty);
- base.FireEditingCanceled();
- }
- public override bool StopEditing()
- {
- if (EditingStopped != null)
- {
- EditingStopped(ckbx, EventArgs.Empty);
- base.FireEditingStopped();
- return true;
- }
- else
- {
- return false;
- }
- }
- public override bool IsReservedKey(KeyEventArgs e)
- {
- return base.IsReservedKey(e);
- }
- public override object IsReservedLocation(Graphics g, int x, int y, Rectangle r, FarPoint.Win.Spread.Appearance appr, object
- value, float zoom)
- {
- return base.IsReservedLocation(g, x, y, r, appr, value, zoom);
- }
- public override Size GetPreferredSize(Graphics g, Size size, FarPoint.Win.Spread.Appearance appr, object value, float zoom)
- {
- return base.GetPreferredSize(g, size, appr, value, zoom);
- }
- public override object Parse(string s)
- {
- return base.Parse(s);
- }
- public override string Format(object o)
- {
- return base.Format(o.ToString());
- }
- public override Control GetEditorControl(FarPoint.Win.Spread.Appearance appearance, float zoomFactor)
- {
- return ckbx;
- }
- public override object GetEditorValue()
- {
- return ckbx.CheckState;
- }
- public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appr, object value, bool issel, bool
- islocked, float zoom)
- {
- GetEditorValue();
- if (ckbx.CheckState == CheckState.Checked)
- {
- ControlPaint.DrawCheckBox(g, r.X, r.Y, r.Width - 40, r.Height - 6, ButtonState.Checked);
- }
- else if (ckbx.CheckState == CheckState.Unchecked)
- {
- ControlPaint.DrawCheckBox(g, r.X, r.Y, r.Width - 40, r.Height - 6, ButtonState.Normal);
- }
- }
- public override void SetEditorValue(object value)
- {
- ckbx.CheckState = CheckState.Checked;
- }
- public override Cursor GetReservedCursor(object o)
- {
- return base.GetReservedCursor(o);
- }
- }
- private void menuItem4_Click(object sender, System.EventArgs e)
- {
- myCkBox ckbx = new myCkBox();
- fpSpread1.ActiveSheet.Cells[0, 0].CellType = ckbx;
- }
复制代码
在获取的时候直接把 fpspread1.EditorControl 转化成 TextBox 即可:
- void fpSpread1_EditModeOn(object sender, EventArgs e)
- {
- TextBox tb = this.fpSpread1.EditingControl as TextBox;
- tb.TextChanged += tb_TextChanged;
- }
复制代码
自定义 TextCellType 基本思路和上面代码相同,大概代码如下。
- private void Form1_Load(object sender, EventArgs e)
- {
- this.fpSpread1.ActiveSheet.Columns[1].CellType = new MyTextBoxCellType();
- }
- GeneralEditor editor;
- void fpSpread1_EditModeOn(object sender, EventArgs e)
- {
- TextBox tb = this.fpSpread1.EditingControl as TextBox;
- tb.TextChanged += tb_TextChanged;
- }
- void tb_TextChanged(object sender, EventArgs e)
- {
-
- }
- public class MyTextBoxCellType : FarPoint.Win.Spread.CellType.TextCellType
- {
- public override Control GetEditorControl(Control parent, FarPoint.Win.Spread.Appearance appearance, float zoomFactor)
- {
- TextBox tx = new TextBox();
- tx.BackColor = Color.Black;
- return tx;
- }
- public override void SetEditorValue(object value)
- {
- base.SetEditorValue(value);
- }
- }
复制代码
有后续问题欢迎继续交流 |