2010-06-18 64 views
0

我正在從pdf文件中嘗試此腳本。如果單擊目標圖像時應將目標圖像更改爲爆炸圖像,但目標圖像不會從常規圖像更改,請將其插入。請幫助!vb6中的圖片更改

Option Explicit 

Dim fiPlayersScore As Integer 
Dim fiNumberofMisses As Integer 
Dim fbTargetHit As Boolean 
Private Sub Form_Load() 
Randomize 
imgTarget.Enabled = False 
imgTarget.Visible = False 
cmdStop.Enabled = False 
lblGameOver.Visible = False 
lblGameOver.Enabled = False 
End Sub 
Private Sub cmdStart_Click() 
Dim lsUserResponse As String 
Dim lbResponse As Boolean 

lsUserResponse = InputBox("Enter a level from 1 to 3." & _ 
(Chr(13)) & "" & (Chr(13)) & "1 being the Easiest and 3 being the " & _ 
"Hardest.", "Level Select", "1") 
lbResponse = False 
If lsUserResponse = "1" Then 
Timer1.Interval = 1500 
lbResponse = True 
ElseIf lsUserResponse = "2" Then 
Timer1.Interval = 1000 
lbResponse = True 
ElseIf lsUserResponse = "3" Then 
Timer1.Interval = 750 
lbResponse = True 
Else 
MsgBox ("Game Not Started.") 
lbResponse = False 
End If 
If lbResponse = True Then 
cmdStart.Enabled = False 
imgTarget.Picture = imgStanding.Picture 

frmMain.MousePointer = 5 
fbTargetHit = False 
Load_Sounds 
cmdStop.Enabled = True 
fiPlayersScore = 0 
fiNumberofMisses = 0 
lblScore.Caption = fiPlayersScore 
lblMisses.Caption = fiNumberofMisses 
Timer1.Enabled = True 
lblGameOver.Visible = False 
lblGameOver.Enabled = False 
End If 
End Sub 

Private Sub cmdStop_Click() 
Unload_Sounds 
frmMain.MousePointer = vbNormal 
Timer1.Enabled = False 
imgTarget.Enabled = False 
imgTarget.Visible = False 
cmdStart.Enabled = True 
cmdStop.Enabled = False 
cmdStart.SetFocus 
lblGameOver.Visible = True 
lblGameOver.Enabled = True 
End Sub 

Private Sub Form_Click() 
MMControl1.Command = "Play" 
MMControl1.Command = "Prev" 
fiNumberofMisses = fiNumberofMisses + 1 
lblMisses.Caption = fiNumberofMisses 
If CheckForLoose = True Then 
cmdStop_Click 
lblMisses.Caption = fiNumberofMisses 
Exit Sub 
End If 
End Sub 

Private Sub imgTarget_Click() 
MMControl2.Command = "Play" 
MMControl2.Command = "Prev" 
Timer1.Enabled = False 
imgTarget.Picture = imgExplode.Picture '**I AM STUCK HERE** 
pauseProgram 

fiPlayersScore = fiPlayersScore + 1 
Timer1.Enabled = True 
If CheckForWin = True Then 
cmdStop_Click 
lblScore.Caption = fiPlayersScore 
Exit Sub 
End If 
lblScore.Caption = fiPlayersScore 
fbTargetHit = True 
imgStanding.Enabled = False 
imgTarget.Visible = False 
imgTarget.Enabled = False 
Timer1.Enabled = True 
End Sub 
Public Sub Load_Sounds() 
'Set initial property values for blaster sound 
MMControl1.Notify = False 
MMControl1.Wait = True 
MMControl1.Shareable = False 
MMControl1.DeviceType = "WaveAudio" 
MMControl1.FileName = _ 
"C:\Temp\Sounds\Blaster_1.wav" 
'Open the media device 
MMControl1.Command = "Open" 

Private Sub Timer1_Timer() 
Dim liRandomLeft As Integer 
Dim liRandomTop As Integer 
imgTarget.Visible = True 
If fbTargetHit = True Then 
fbTargetHit = False 
imgTarget.Picture = imgStanding.Picture 
End If 
liRandomLeft = (6120 * Rnd) 
liRandomTop = (4680 * Rnd) 
imgTarget.Left = liRandomLeft 
imgTarget.Top = liRandomTop 
imgTarget.Enabled = True 
imgTarget.Visible = True 
End Sub 

Public Function CheckForWin() As Boolean 
CheckForWin = False 
If fiPlayersScore = 5 Then 
CheckForWin = True 
lblGameOver.Caption = "You Win.Game Over" 
End If 
End Function 
Public Function CheckForLoose() As Boolean 
CheckForLoose = False 
If fiNumberofMisses = 5 Then 
CheckForLoose = True 
lblGameOver.Caption = "You Loose.Game Over" 
End If 
End Function 

Private Sub Form_QueryUnload(Cancel As Integer, _ 
UnloadMode As Integer) 
Unload_Sounds 
End Sub 
Public Sub Unload_Sounds() 
MMControl1.Command = "Close" 
MMControl2.Command = "Close" 
End Sub 
Public Sub pauseProgram() 
Dim currentTime 
Dim newTime 
currentTime = Second(Time) 
newTime = Second(Time) 
Do Until Abs(newTime - currentTime) >= 1 
newTime = Second(Time) 
Loop 
End Sub 

回答

0

編輯:

imgTarget.Picture = imgExplode.Picture 
imgTarget.Refresh 
+0

這是用於多個圖像和自動加載與計時器 – 2010-06-18 14:20:35

+0

爲什麼不只是從您的點擊事件的圖像列表中加載一個新的圖像。 – renick 2010-06-18 14:27:03

+0

我無法找到圖像列表控件 – 2010-06-19 06:23:03

0

注:

Set imgTarget.Picture = imgExplode.Picture 
imgTarget.Refresh 

將快於

imgTarget.Picture = imgExplode.Picture 
imgTarget.Refresh 

如果imgExplode會imgTarget的壽命期間各地(的第一個命令複製圖像t他設置命令引用圖像)。

+0

對不起克里斯,在回答問題 – 2010-06-26 11:29:08

+0

稍遲,我沒有回答這個問題,我正在添加額外的信息... – 2010-06-27 15:27:09