找回密码
 立即注册

QQ登录

只需一步,快速开始

darkelf
论坛元老   /  发表于:2013-11-1 17:08  /   查看:11288  /  回复:10
求教,如何在Spread Win Form7 中处理旧版本的ButtonClicked事件?

新的ButtonClicked事件的响应范围以及事件消息类型都跟旧版本不同。
特别是ButtonDown这个事件属性,该如何获取?

以下是自定义事件的相关内容。


  1. Public Shadows Event ButtonClicked(ByVal sender As Object, ByVal e As _DSpreadEvents_ButtonClickedEvent)

  2. Private Sub MyBase_ButtonClicked(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles MyBase.ButtonClicked
  3.         Dim buttonDown As Integer = 0
  4.         '追加旧Spread的ButtonClicked事件参数ButtonDown

  5.   '根据旧版本资料,Cell类型是复选框的时候,ButtonDown属性仅在复选框为选择或者灰色状态时为1
  6.   ' Cell类型是按钮时,ButtonDown属性,仅在按钮被按下状态时,返回True。

  7.         If checkButtonDown(e.Row, e.Column) = True Then
  8.             buttonDown = 1
  9.         End If
  10.         Dim args = New _DSpreadEvents_ButtonClickedEvent(e.Column, e.Row, buttonDown)

  11.         RaiseEvent ButtonClicked(sender, args)
  12.     End Sub

  13.     ' 增加判断函数,创建ButtonDown属性
  14.     Private Function checkButtonDown(ByVal row As Integer, ByVal col As Integer) As Boolean
  15.         If MyBase.ActiveSheet IsNot Nothing Then
  16.             If TypeOf MyBase.ActiveSheet.Cells(row, col).CellType Is CellType.CheckBoxCellType Then

  17.                 '复选框状态为选择,灰色的时候, ButtonDown = True
  18.                 If MyBase.ActiveSheet.Cells(row, col).Value <> 0 Then
  19.                     Return True
  20.                 End If
  21.             ElseIf TypeOf MyBase.ActiveSheet.Cells(row, col).CellType Is CellType.ButtonCellType Then
  22.                 ' 问题: 如何获得按钮为按下状态?
  23.                 Return True
  24.             End If
  25.         End If

  26.         Return False
  27.     End Function

  28. ''' <summary>
  29.     ''' 自定义消息类型ButtonClicked
  30.     ''' </summary>
  31.     ''' <remarks></remarks>
  32.     Public Class _DSpreadEvents_ButtonClickedEvent
  33.         '列
  34.         Private _Col As Integer
  35.         '行
  36.         Private _Row As Integer
  37.         '按钮
  38.         Private _ButtonDown As Integer

  39.         ''' <summary>
  40.         ''' 构造函数
  41.         ''' </summary>
  42.         ''' <param name="col">列</param>
  43.         ''' <param name="row">行</param>
  44.         ''' <remarks></remarks>
  45.         Public Sub New(ByVal col As Integer, ByVal row As Integer, ByVal button As Integer)
  46.             Me._Col = col + 1
  47.             Me._Row = row + 1
  48.             Me._ButtonDown = button
  49.         End Sub

  50.         ''' <summary>
  51.         ''' 列
  52.         ''' </summary>
  53.         ''' <value></value>
  54.         ''' <returns></returns>
  55.         ''' <remarks></remarks>
  56.         Public Property Col() As Integer
  57.             Get
  58.                 Return _Col + 1
  59.             End Get
  60.             Set(value As Integer)
  61.                 _Col = value
  62.             End Set
  63.         End Property

  64.         ''' <summary>
  65.         ''' 行
  66.         ''' </summary>
  67.         ''' <value></value>
  68.         ''' <returns></returns>
  69.         ''' <remarks></remarks>
  70.         Public Property Row() As Integer
  71.             Get
  72.                 Return _Row + 1
  73.             End Get
  74.             Set(value As Integer)
  75.                 _Row = value
  76.             End Set
  77.         End Property

  78.         ''' <summary>
  79.         ''' 按钮状态
  80.         ''' </summary>
  81.         ''' <value></value>
  82.         ''' <returns></returns>
  83.         ''' <remarks></remarks>
  84.         Public Property ButtonDown() As Integer
  85.             Get
  86.                 Return _ButtonDown
  87.             End Get
  88.             Set(value As Integer)
  89.                 _ButtonDown = value
  90.             End Set
  91.         End Property
  92.     End Class
复制代码


请不吝赐教。

10 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-11-1 18:40:00
沙发
回复 1楼darkelf的帖子

darkelf 你好,
Spread Win Form7 中也同样有 ButtonClicked 事件:

  1.   public Form2()
  2.         {
  3.             InitializeComponent();
  4.             this.fpSpread1.Sheets[0].Cells[0, 0].CellType = new FarPoint.Win.Spread.CellType.ButtonCellType();
  5.             this.fpSpread1.ButtonClicked += new FarPoint.Win.Spread.EditorNotifyEventHandler(fpSpread1_ButtonClicked);
  6.         }

  7.         void fpSpread1_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
  8.         {
  9.             throw new NotImplementedException();
  10.         }
复制代码
回复 使用道具 举报
darkelf
论坛元老   /  发表于:2013-11-5 08:15:00
板凳
iceman 您好

也就是说,利用您给出的方法,Spread Win Form7的BUttonClicked事件也可以获取到ButtonDown属性是吗?现在去测试一下。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-5 10:39:00
地板
回复 3楼darkelf的帖子

是的可以,测试结果如何?
回复 使用道具 举报
darkelf
论坛元老   /  发表于:2013-11-5 12:15:00
5#
结果还是不可以呀。

ButtonClicked的消息类型EditorNotifyEventArgs,获得不了ButtonDown的说。

可以具体说一下如何从最新的消息类型EditorNotifyEventArgs中取得旧版本Spread的ButtonDown属性的方法吗?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-5 18:40:00
6#
回复 5楼darkelf的帖子

darkelf 你好,
请问你之前使用的是什么版本?我理解 ButtonDown 是获取单元格中按钮点击事件。测试代码如下:

  1. public Form1()
  2.         {
  3.             InitializeComponent();
  4.             this.fpSpread1.ButtonClicked += new FarPoint.Win.Spread.EditorNotifyEventHandler(fpSpread1_ButtonClicked);
  5.             this.fpSpread1.Sheets[0].Columns[0].CellType = new FarPoint.Win.Spread.CellType.ButtonCellType();
  6.         }

  7.         void fpSpread1_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
  8.         {

  9.         }
复制代码
回复 使用道具 举报
darkelf
论坛元老   /  发表于:2013-11-6 08:43:00
7#
具体版本不清楚。 只能说旧VB6程序中的ButtonClicked事件触发后,
在具体处理部分,有ButtonDown属性的判断分支流程。
  1. Private Sub vaSpread2_ButtonClicked(ByVal Col As Long, ByVal Row As Long, ByVal ButtonDown As Integer)
  2. If ButtonDown = 1 Then
  3.     Process1
  4. Else
  5.     Proccess2
  6. End IF
复制代码

然后在搜索关于ButtonClicked事件的时候,有得到这个事件的相关说明。
英文,ActiceX Spread8的说明,但是跟目前VB6实装的条件接近。我认为很可能就是这个。

http://www.gcpowertools.com/help/SpreadCOM/events14.html#510837

ButtonClicked事件
  在按钮单元格或者CheckBox单元格,按下时候触发事件。
  其中ButtonDown的类型为NUMBER。按钮按下时为True,其他时间为False; CheckBox的ThreeState状态为选择,备选的时候,ButtonDown为True,
非选择时候为False。

现在的情况是,按钮单元格和CheckBox单元格无论何时按下,都会触发事件,然后却无法获取ButtonDown属性。

在VB6的旧版中,只有ButtonDown为1(True)的时候;以及0(False)时,需要分别处理。所以在这里卡住了。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-6 13:07:00
8#
回复 7楼darkelf的帖子

ButtonCellType 也提供双态显示模式,可通过 FpButton 来判断当前状态:

  1. public Form1()
  2.         {
  3.             InitializeComponent();
  4.             this.fpSpread1.ButtonClicked += new FarPoint.Win.Spread.EditorNotifyEventHandler(fpSpread1_ButtonClicked);

  5.             FarPoint.Win.Spread.CellType.ButtonCellType bttncell = new FarPoint.Win.Spread.CellType.ButtonCellType();
  6.             //设置 button 双模显示
  7.             bttncell.TwoState = true;
  8.             
  9.             //未按下文本
  10.             bttncell.Text = &quot;Click and hold...&quot;;
  11.             //按下文本
  12.             bttncell.TextDown = &quot;...you can see how words go to multiple lines. Now let go.&quot;;
  13.             bttncell.TextColor = Color.Green;
  14.             bttncell.WordWrap = true;
  15.             fpSpread1.Sheets[0].Cells[3, 2].CellType = bttncell;
  16.         }

  17.         void fpSpread1_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
  18.         {
  19.             FpButton fpbtn = e.EditingControl as FpButton;
  20.             if (fpbtn.Value==1)
  21.             {
  22.                 MessageBox.Show(&quot;button已经按下&quot;);
  23.             }
  24.             else
  25.             {
  26.                 MessageBox.Show(&quot;button未按下&quot;);

  27.             }
  28.         }
复制代码
回复 使用道具 举报
darkelf
论坛元老   /  发表于:2013-11-6 14:15:00
9#
了解。非常感谢。
这样子就能完全获得需要的消息了。
回复 使用道具 举报
darkelf
论坛元老   /  发表于:2013-11-6 14:26:00
10#
完全正确的获取按钮消息了。
再次感恩。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部