我在VB开始一个新项目。我有一个问题。所以也许我不理解逻辑 - 你能解释一下吗?
在我的函数Feuil1_BeforeDoubleClick
中,我想等待Button1_Click
结束。
但我不知道如何实现这一目标。
以下是相关代码:
我的Sheet1
:
Imports System.Threading.Tasks
Imports Microsoft.Office.Interop.Excel
Public Class Feuil1
Friend actionsPane1 As New ActionsPaneControl1
Public list As String
Public Sub Feuil1_BeforeDoubleClick(Target As Range, ByRef Cancel As Boolean) Handles Me.BeforeDoubleClick
If Target.Column <> 1 Then
If Target.Row = 16 Then
Globals.ThisWorkbook.ActionsPane.Controls.Add(actionsPane1)
Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = True
'marche pas SendKeys.Send("{ESC}")
'
'wait here for the end of Button1_click
Target.Value = list
list = ""
End If
End If
MsgBox("doubleclick end")
End Sub
End Class
还有我的actionpane1
:
Public Class ActionsPaneControl1
Friend Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer
Dim itemChecked As Object
Const barre As String = " / "
For Each itemChecked In CheckedListBox1.CheckedItems
Globals.Feuil1.list = Globals.Feuil1.list + itemChecked.ToString() + barre
Next
' Boucle pour reset la list
For i = 0 To (CheckedListBox1.Items.Count - 1)
CheckedListBox1.SetItemChecked(i, False)
Next
Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = False
End Sub
End Class
答案 0 :(得分:1)
取自https://www.daniweb.com/programming/software-development/threads/139395/how-to-check-if-a-button-was-clicked的示例。给予信用。 在表单级别基本声明一个变量,然后在单击按钮时将其设置为true。适当时重置
Dim bBtnClicked As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If bBtnClicked = True Then
MessageBox.Show("This button is clicked already ....")
Else
MessageBox.Show("This button is clicked First time ....")
End If
bBtnClicked = True
End Sub
或者,无论您希望在单击按钮后发生什么,只需将该代码放在按钮单击事件的处理程序中即可。
答案 1 :(得分:0)
所以我想到了这个问题,似乎我没有理解我的功能doubleclick,在双击之后但之前没有工作!这是我的错误。
所以我改变我的功能来检测我的表格中的选择变化。 然后我打电话给我的行动窗格。 并使用操作窗格按钮的事件。
有完整的代码(也许是因为我没有正确解释我)
我的Sheet1.vb
:
Imports Microsoft.Office.Interop.Excel
Public Class Feuil1
Friend actionsPane1 As New ActionsPaneControl1
Public list As String
Public cell As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Handles Me.SelectionChange
If Target.Column <> 1 Then
If Target.Row = 16 Then
Globals.ThisWorkbook.ActionsPane.Controls.Add(actionsPane1)
Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = True
cell = Target
End If
End If
End Sub
End Class
和我的actionpanecontrol1.vb
:
Public Class ActionsPaneControl1
Friend Button1Click = False
Friend Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer
Dim itemChecked As Object
Const barre As String = " / "
For Each itemChecked In CheckedListBox1.CheckedItems
Globals.Feuil1.list = Globals.Feuil1.list + itemChecked.ToString() + barre
Next
' Boucle pour reset la list
For i = 0 To (CheckedListBox1.Items.Count - 1)
CheckedListBox1.SetItemChecked(i, False)
Next
Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = False
Button1Click = True
Globals.Feuil1.cell.Value = Globals.Feuil1.list
Globals.Feuil1.list = ""
End Sub
End Class
非常感谢您的回复