-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfrmSetTimer.frm
128 lines (120 loc) · 4.39 KB
/
frmSetTimer.frm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
VERSION 5.00
Begin VB.Form frmSetTimer
BorderStyle = 1 'Fixed Single
Caption = "计时器选项"
ClientHeight = 1620
ClientLeft = 45
ClientTop = 375
ClientWidth = 3990
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1620
ScaleWidth = 3990
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton cmdCancel
Caption = "取消"
Height = 375
Left = 2168
TabIndex = 2
Top = 1080
Width = 1095
End
Begin VB.CommandButton cmdOK
Caption = "确定"
Height = 375
Left = 728
TabIndex = 1
Top = 1080
Width = 1095
End
Begin VB.TextBox edInterval
Height = 285
Left = 2160
TabIndex = 0
Top = 600
Width = 1335
End
Begin VB.TextBox edTimerID
Height = 285
Left = 2160
Locked = -1 'True
TabIndex = 3
Text = "1"
Top = 120
Width = 1335
End
Begin VB.Label labTip
Alignment = 1 'Right Justify
AutoSize = -1 'True
Caption = "计时间隔(毫秒):"
Height = 195
Index = 1
Left = 480
TabIndex = 5
Top = 600
Width = 1620
End
Begin VB.Label labTip
AutoSize = -1 'True
Caption = "计时器ID(自动分配):"
Height = 195
Index = 0
Left = 120
TabIndex = 4
Top = 120
Width = 1965
End
End
Attribute VB_Name = "frmSetTimer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public IsAdding As Boolean '当前是否往列表中添加项目,如果为否则是更改列表中的项目
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim AddedItem As ListItem '添加的列表项
If IsNumeric(Me.edInterval.Text) And Val(Me.edInterval.Text) >= 0 Then '判断输入的内容是否合法
If IsAdding Then '添加计时器状态
Set AddedItem = frmTimerList.lstTimer.ListItems.Add(, , Me.edTimerID.Text) '计时器ID
AddedItem.SubItems(1) = CStr(CLng(Me.edInterval.Text)) '计时器计时间隔
AddedItem.SubItems(2) = "Timer_" & Me.edTimerID.Text & "_Timer()" '计时器对应代码
Set frmTimerList.lstTimer.SelectedItem = AddedItem '让列表框选择刚刚添加的列表项
Else '更改计时器状态
frmTimerList.lstTimer.SelectedItem.SubItems(1) = CStr(CLng(Me.edInterval.Text)) '更改计时器计时间隔
End If
Call frmMain.mnuToCode_Click '跳转到本计时器对应的代码
IsSaved = False '记录当前工程已更改
Unload Me
Else '不合法的输入内容
MsgBox "无效的计时间隔!", 48, "错误"
Me.edInterval.SelStart = 0
Me.edInterval.SelLength = Len(Me.edInterval.Text)
Me.edInterval.SetFocus
End If
End Sub
Private Sub edInterval_KeyPress(KeyAscii As Integer)
'按下Enter键则按下确定按钮
If KeyAscii = vbKeyReturn Then
cmdOK_Click
End If
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
'按下Esc键则关闭窗体
If KeyAscii = vbKeyEscape Then
KeyAscii = 0
Unload Me
End If
End Sub
Private Sub Form_Load()
SetWindowLong Me.edInterval.hwnd, GWL_STYLE, GetWindowLong(Me.edInterval.hwnd, GWL_STYLE) Or ES_NUMBER '只允许数字输入
End Sub
Private Sub Form_Unload(Cancel As Integer)
frmMain.Enabled = True
frmMain.SetFocus
End Sub