請教大神:
1.將一個PictureBox做成幀影片(用timeGetTime來延遲LoadPicture從而逐幀實作)
2.將這個PictureBox進行持續位移(用timeGetTime來延遲持續改變其Left值)
那么問題來了:
位移時,原本進行的幀影片會暫停.
或者幀影片時,原來進行的位移會暫停
各自都使用了DoEvent也沒用
請問有解決方案嗎?
不能貼附件,只能貼個范例的代碼:
1.這是我picturebox實作的幀影片(IMG檔案夾內的1.gif 2.gif 3.gif是我設定3張靜態gif圖片)
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Sub Img1_LoadPic()
Dim Cycle As Integer
Dim PicNum As Integer
Dim Savetime As Double
For Cycle = 1 To 10
For PicNum = 1 To 3
Image1.Picture = LoadPicture(ThisWorkbook.Path & "\IMG\" & PicNum & ".gif")
DoEvents
Savetime = timeGetTime
While timeGetTime < Savetime + 500
DoEvents
Wend
Next
Next
End Sub
2.這是我實作的picturebox持續位移
兩個同時運行時會中斷另一個
請問有解決方案可以兩個sub同時產生效果么?
大神教我怎么改~~~
Sub Img1_Mov()
Dim Savetime As Double
Dim NowMovNum As Integer
Dim AddMovNum As Integer
Dim AddValue As Integer
For AddValue = 1 To 5
NowMovNum = Image1.Left
AddMovNum = NowMovNum + AddValue
Image1.Left = AddMovNum
DoEvents
Savetime = timeGetTime
While timeGetTime < Savetime + 500
DoEvents
Wend
Next
End Sub
uj5u.com熱心網友回復:
在vba里模擬顯示影片,多費勁啊。直接上個webbrowser控制元件不好嗎?uj5u.com熱心網友回復:
用任務佇列:1)先定義一個任務介面
'ITask
Option Explicit
'任務是否運行中'
Public Property Get Enabled() As Boolean
End Property
'下個觸發時點'
Public Property Get NextTime() As Long
End Property
'達到觸發時點時被呼叫。'
'顯示下一幀影片或下一步移動。'
'同時需要增加NextTime的值,如果影片/移動結束則設Enabled為False'
Public Sub OnTimer()
End Sub
2)影片/移動分別做成實作ITask介面的Class
3)呼叫的方式如下
Private Sub RunTasks()
Dim colTasks As Collection
Dim cTask As ITask
Dim lTime As Long
Dim bOnTimer As Boolean
Dim lEnabledCount As Long
Set colTasks = New Collection
'初始化影片/移動的任務實體,加入colTasks集合'
Do
lTime = timeGetTime()
lEnabledCount = 0
bOnTimer = False
For Each cTask In colTasks
If cTask.Enabled Then
If lTime >= cTask.NextTime Then
cTask.OnTimer
bOnTimer = True
If cTask.Enabled Then
lEnabledCount = lEnabledCount + 1
End If
Else
lEnabledCount = lEnabledCount + 1
End If
End If
Next
If bOnTimer Then
DoEvents
End If
Loop While lEnabledCount > 0
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/108048.html
標籤:VBA
上一篇:求助:vb中怎么來判斷UDP包的包頭,并根據包頭中所包含的資訊把UDP包里面的資料放到陣列里
下一篇:關于亂數種子的問題
