懂VB的进,帮我看看一小段代码哪里出问题了~ 谢谢 先给30分

2025-05-20 00:49:04
推荐回答(1个)
回答1:

我试了你的代码,发现一切正常啊,可能是4个Option不再同一个容器里,你可以把4个Option删除了,重新在左边工具箱重新双击点4个Option出来。
不然你用这个msgbox 代替关机的命令,看看你是在哪部分运行到了关机的代码,代码如下,好了记得给分啊,
Private Declare Function GetForegroundWindow Lib "User32" () As Long 'api声明
Private Sub Command1_Click()
If Option1.Value = True Then
MsgBox "10"
' Shell "cmd.exe /c shutdown -s -t 10"
Option1.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
ElseIf Option2.Value = True Then
' Shell "cmd.exe /c shutdown -s -t 20"
MsgBox "20"
Option1.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
ElseIf Option3.Value = True Then
' Shell "cmd.exe /c shutdown -s -t 30"
MsgBox "30"
Option1.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
ElseIf Option4.Value = True Then
' Shell "cmd.exe /c shutdown -s -t 0"
MsgBox "0"
Option4.Enabled = False
Else
' Shell "cmd.exe /c shutdown -s -t 0"
MsgBox "00"
End If

End Sub
Private Sub Command2_Click()
Shell "cmd.exe /c shutdown -s -t 5"
End Sub

Private Sub Form_Load()
Timer1.Interval = 100 '设置定时器延时100毫秒
Label1.Caption = "Good luck!"
End Sub

Private Sub Timer1_Timer()
If GetForegroundWindow <> Me.hWnd Then '判断获取的句柄与本窗体的句柄是否一致
'Shell "cmd.exe /c shutdown -s -t 5"
MsgBox "5"
End If
End Sub