Dim i As Integer i = Button.Index MsgBox Button.Caption Dim bt As Button For Each bt In Toolbar1.Buttons If bt.Index + 1 = i Then Toolbar1_ButtonClick bt Exit For End If Next
看这里Private isClick As Boolean Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Dim i As Integer MsgBox Button.Caption & " " & isClick '这路你可以换成call一个过程 If Not isClick Then i = Button.Index Dim bt As Button For Each bt In Toolbar1.Buttons If bt.Index + 1 = i Then isClick = True Toolbar1_ButtonClick bt isClick = False Exit For End If Next End If
End Sub
最简单的办法就是在Toolbar1_ButtonClick事件里让一个无关控件获得焦点 Private Sub Text1_LostFocus() MsgBox "1" End SubPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Text2.SetFocus End Sub
按我的理解是这样的,VB中的Toolbar不拥有焦点,也就是说它不夺取其它控件的焦点,所以也就没办法触发lostfocus事件了。你可以试一下: 在窗口中加一个Toolbar,加一个Command1,无论你何时点击工具条,下面代码显示的两个句柄都是相同的。 Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Debug.Print Me.ActiveControl.hWnd, Command1.hWnd End Sub
To:songyaowu 難道還沒有人解決渦此問題?
Private Sub toolBar_LostFocus() If bolCancel Then Exit Sub MSFGFab.TextMatrix(MSFGFab.Row, 7) = IIf(Trim(txtQTY.Text) = "", 0, Trim( txtQTY.Text)) Call SaveFabTmpVal(7, Trim(IIf(Trim(txtQTY.Text) = "", 0, Trim(txtQTY.Text)))) End Sub 當鼠標移開是觸發LostFocus事件
i = Button.Index
MsgBox Button.Caption
Dim bt As Button
For Each bt In Toolbar1.Buttons
If bt.Index + 1 = i Then
Toolbar1_ButtonClick bt
Exit For
End If
Next
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim i As Integer
MsgBox Button.Caption & " " & isClick '这路你可以换成call一个过程
If Not isClick Then
i = Button.Index
Dim bt As Button
For Each bt In Toolbar1.Buttons
If bt.Index + 1 = i Then
isClick = True
Toolbar1_ButtonClick bt
isClick = False
Exit For
End If
Next
End If
End Sub
Private Sub Text1_LostFocus()
MsgBox "1"
End SubPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Text2.SetFocus
End Sub
我还是不太明白你的意思
我还以为你是说点了TOOLBAR上面的按钮触发上一个按钮
那样的代码可以帮助你,如果你是在单击TOOLBAR而触发上个失去焦点的LOSTFOCUS事件的话根本就直接在上个控件的LOSTFOCUS事件中添加代码就行了
在窗口中加一个Toolbar,加一个Command1,无论你何时点击工具条,下面代码显示的两个句柄都是相同的。
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Debug.Print Me.ActiveControl.hWnd, Command1.hWnd
End Sub
難道還沒有人解決渦此問題?
If bolCancel Then Exit Sub
MSFGFab.TextMatrix(MSFGFab.Row, 7) = IIf(Trim(txtQTY.Text) = "", 0,
Trim( txtQTY.Text))
Call SaveFabTmpVal(7, Trim(IIf(Trim(txtQTY.Text) = "", 0, Trim(txtQTY.Text))))
End Sub
當鼠標移開是觸發LostFocus事件