重写Render画一个图标,例子里我就画了个方块,然后事件里判断是不是点的图标,执行操作。
- fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 0].Renderer = new MyColumnHeaderRenderer();
- fpSpread1.CellClick += FpSpread1_CellClick;
复制代码
- private void FpSpread1_CellClick(object sender, CellClickEventArgs e)
- {
- if (e.ColumnHeader)
- {
- if(fpSpread1.ActiveSheet.ColumnHeader.Cells[e.Row, e.Column].Renderer is MyColumnHeaderRenderer)
- {
- var r = e.View.GetColumnHeaderCellRectangle(0, e.Row, e.Column);
- if (e.X>= r.X + r.Width - 30 && e.X<= r.X + r.Width - 30+15
- && e.Y>= r.Y + (r.Height - 15) / 2 &&e.Y<= r.Y + (r.Height - 15) / 2 + 15)
- {
- MessageBox.Show("Ha");
- e.Cancel = true;
- }
- }
- }
- }
复制代码
- public class MyColumnHeaderRenderer : FarPoint.Win.Spread.CellType.ColumnHeaderRenderer
- {
- // Override the sorting indicator paint method.
- public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
- {
- base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
- Pen p = new Pen(Brushes.Red);
- g.DrawRectangle(p, r.X + r.Width - 30, r.Y + (r.Height - 15) / 2, 15, 15);
- }
-
- }
复制代码 |