我有一個我在VB 2010中開發的應用程序。它由一系列Windows窗體和一個偵聽器進程組成,它監聽來自MIDI設備(鍵盤等等)。此偵聽器進程在單獨的線程中運行。如何從遠程線程觸發WinForms按鈕點擊
使用回調函數和調用方法我可以使用MIDI設備上演奏的音符的值(代碼如下)更新其中一個窗體上的文本框的值。
我似乎無法做到的是觸發按鈕之一按鈕,以便一段代碼使用另一個回調函數在同一窗體上運行並調用。
我搜索了一下,找不到任何工作示例,所以我不確定這是否可行 - 我希望這是因爲這是我項目的最後1%!
下面是更新窗體上的文本框的工作,我需要修改什麼才能點擊名爲btn_NextSection的同一窗體上的按鈕?
' Because the MIDI listener process runs in a different thread
' it can read the states of controls on the parent form but it
' cannot modify them so we need to identify the parent process
' and update the text box as that one instead
' Set up the callback
Private Delegate Sub SetNextSectionTextCallback(ByVal [text] As String)
' Updates NextSection
Private Sub SetNextSectionText(ByVal [text] As String)
' Function to see if the thread that tries to update the
' text box is the same as the one that started it. If it
' isn't then locate parent process and update as that one
If callerInstance.txt_NextSection.InvokeRequired Then
Dim d As New SetNextSectionTextCallback(AddressOf SetNextSectionText)
callerInstance.Invoke(d, New Object() {[text]})
Else
callerInstance.txt_NextSection.Text = [text]
End If
End Sub
在此先感謝!
所以你想模擬被點擊的按鈕的外觀(視覺效果?),或者你想觸發在click事件中運行的代碼。 – PatFromCanada 2013-04-23 15:22:32