【问题标题】:How to trigger button through code in devexpress?如何通过devexpress中的代码触发按钮?
【发布时间】:2012-02-11 14:27:21
【问题描述】:

此代码可以正常使用普通按钮,但 devexpress 中的按钮给我提供了一些错误。 它说 sender 和 e 没有声明..

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
    Select Case keyData
        Case Keys.Enter
              btnPayment_Click(sender, e)
        Case Keys.F2

        Case Keys.F5


        Case Keys.F6


        Case Keys.Escape
            Me.Close()

        Case Else
            Return MyBase.ProcessCmdKey(msg, keyData)
    End Select

    Return True
End Function

【问题讨论】:

    标签: .net vb.net winforms devexpress


    【解决方案1】:

    在 VB 2010 中,我使用了 PerformClick。这对你有用吗?前任。 btnPayment.PerfformClick()

    【讨论】:

      【解决方案2】:

      您正试图通过传递两个未声明的变量(sender,e)来调用 btnPayment_Click 处理程序。

      如果您只想执行 btnPayment_Click 中的代码并且 它不依赖于 sender 参数或 e 参数,那么您仍然需要传递一些东西 - 即:

      btnPayment_Click(null, null)
      

      更好的结构可能是这样的:

      protected void btnTest_Click(object sender, EventArgs e)
      {
         SomeSub();
      }
      
      protected void SomeOtherFunctionThatNeedsToCallTheCode()
      {
         SomeSub();
      }
      
      protected void SomeSub()
      {
         // ...
      }
      

      见:C#: calling a button event handler method without actually clicking the button

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-04-10
        • 2020-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-08
        • 2021-06-04
        相关资源
        最近更新 更多