找回密码
 立即注册

QQ登录

只需一步,快速开始

lkxtracy

金牌服务用户

12

主题

57

帖子

195

积分

金牌服务用户

积分
195

[已处理] 按钮单元格问题

lkxtracy
金牌服务用户   /  发表于:2019-1-23 19:18  /   查看:2799  /  回复:3
请问如何实现图片中的单元格效果。
目前尝试两种办法
1.

fpSpread1_Sheet1.Cells[1,1].CellType = new GcTextBoxCellType()
            {
                SideButtons = new SideButtonCollectionInfo()
                {
                    new SideButtonInfo()
                    {
                        Enabled = true,
                        Interval = 1,
                        Text = "选",
                        ButtonWidth = 25
                    }
                }
            };

这种方式找不到接口响应Click事件

2.自定义单元格类型
public class ContentCellButton : FarPoint.Win.Spread.CellType.ButtonCellType
    {
        public override void PaintCell(System.Drawing.Graphics g, System.Drawing.Rectangle r,
            FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
        {
            Rectangle _rectangle = new Rectangle(r.Right - 25, r.Y, 25, r.Height);

            base.PaintCell(g, _rectangle, appearance, value, isSelected, isLocked, zoomFactor);
        }
    }


这种方式实现,当单元格选中时,按钮还是会覆盖整个单元格

效果图

效果图

3 个回复

倒序浏览
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-1-24 09:24:36
沙发
在EditModeOn事件中给sidebutton 挂click事件

  1.             fpSpread1_Sheet1.Cells[1, 1].CellType = new GcTextBoxCellType()
  2.             {
  3.                 SideButtons = new SideButtonCollectionInfo()
  4.                 {
  5.                     new SideButtonInfo()
  6.                     {
  7.                         Enabled = true,
  8.                         Interval = 1,
  9.                         Text = "选",
  10.                         ButtonWidth = 25,
  11.                           Name = "testbutton"
  12.                     },
  13.                 },
  14.             };
  15.             fpSpread1.EditModeOn += FpSpread1_EditModeOn;
复制代码


  1.         private void FpSpread1_EditModeOn(object sender, EventArgs e)
  2.         {
  3.             int iRow = fpSpread1.ActiveSheet.ActiveRowIndex;
  4.             int iCol = fpSpread1.ActiveSheet.ActiveColumnIndex;
  5.             if (fpSpread1.ActiveSheet.GetCellType(iRow, iCol) is GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType)
  6.             {
  7.                 (fpSpread1.EditingControl as GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxEditingControl).SideButtons["testbutton"].Click -= new EventHandler(sideButtonClick);
  8.                 (fpSpread1.EditingControl as GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxEditingControl).SideButtons["testbutton"].Click += new EventHandler(sideButtonClick);
  9.             }
  10.         }
复制代码
回复 使用道具 举报
lkxtracy
金牌服务用户   /  发表于:2019-1-24 16:16:59
板凳
多谢大神!
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-1-24 18:40:09
地板
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部