📄 mainform.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "事件的设计"
ClientHeight = 5325
ClientLeft = 45
ClientTop = 270
ClientWidth = 7605
LinkTopic = "Form1"
ScaleHeight = 5325
ScaleWidth = 7605
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtReceive
Height = 2055
Left = 4080
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 6
Top = 720
Width = 3015
End
Begin VB.CommandButton Command1
Caption = "清空接收区"
BeginProperty Font
Name = "Tahoma"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 924
Left = 4176
Picture = "Mainform.frx":0000
Style = 1 'Graphical
TabIndex = 5
Top = 2805
Width = 2412
End
Begin MSCommLib.MSComm Comm1
Left = 2640
Top = 120
_ExtentX = 794
_ExtentY = 794
_Version = 393216
DTREnable = -1 'True
RThreshold = 1
End
Begin VB.CommandButton CmdExit
Cancel = -1 'True
Caption = "退出"
BeginProperty Font
Name = "Tahoma"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 876
Left = 2352
Picture = "Mainform.frx":0442
Style = 1 'Graphical
TabIndex = 4
Top = 4110
Width = 2652
End
Begin VB.CommandButton CmdSend
Caption = "发送字符"
BeginProperty Font
Name = "Tahoma"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 924
Left = 768
Picture = "Mainform.frx":0884
Style = 1 'Graphical
TabIndex = 3
Top = 2805
Width = 2460
End
Begin VB.TextBox txtSend
BeginProperty Font
Name = "Times New Roman"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1860
Left = 672
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Text = "Mainform.frx":0B8E
Top = 720
Width = 2940
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "接收区"
BeginProperty Font
Name = "Tahoma"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Index = 1
Left = 4080
TabIndex = 2
Top = 360
Width = 720
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "发送区"
BeginProperty Font
Name = "Tahoma"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Index = 0
Left = 765
TabIndex = 1
Top = 360
Width = 720
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
''''''''''''''''''''''''''''''''''''''
'使用命令按钮控制项
'关闭通讯埠
'结束系统
''''''''''''''''''''''''''''''''''''''
Private Sub CmdExit_Click()
Comm1.PortOpen = False
End
End Sub
''''''''''''''''''''''''''''''''''''''
'使用命令按钮控制项
'使用Input属性读取串列埠的传入值
'并将结果显示在Label控制的Caption属性里
''''''''''''''''''''''''''''''''''''''
Private Sub CmdReceive_Click()
Dim buf$
buf = Trim(Comm1.Input)
If Len(buf) = 0 Then
txtReceive.Text = "Empty"
Else
txtReceive.Text = buf & vbCr
End If
End Sub
''''''''''''''''''''''''''''''''''''''
'使用命令按钮控制项
'使用Output属性将使用者欲传送的字串送出
''''''''''''''''''''''''''''''''''''''
Private Sub CmdSend_Click()
Comm1.Output = Trim(txtSend.Text)
End Sub
''''''''''''''''''''''''''''''''''''''
'MSComm的OnComm事件程序
'由CommEvent属性值的不同,将各别的程式码写入
'相关的副程式中
'在此例中,只要RThresold中的设定字元数到达时
'便会使得CommEvent属性值变成comEvReceive
'因此接收的副程式便被执行
''''''''''''''''''''''''''''''''''''''
Private Sub Comm1_OnComm()
Select Case Comm1.CommEvent
' 藉着取代底下每一个 case 陈述式来处理每个事件与错误
' 事件
Case comEvCD ' CD 线的状态发生变化.
Case comEvCTS ' CTS 线的状态发生变化.
Case comEvDSR ' DSR 线的状态发生变化.
Case comEvRing ' Ring Indicator 变化.
Case comEvReceive ' 收到 RThreshold # of
txtReceive.Text = txtReceive.Text + Trim(Comm1.Input)
Case comEvSend ' 传输暂存区有 Sthreshold 个字元 '
End Select
End Sub
''''''''''''''''''''''''''''''''''''''
'使用命令按钮控制项
'将接收区的显示范围清空
''''''''''''''''''''''''''''''''''''''
Private Sub Command1_Click()
txtReceive = ""
End Sub
''''''''''''''''''''''''''''''''''''''
'表单的载入事件
'开启串列通讯埠,参数亦可在开启之前先行指定,
'指定完後,再开启该通讯埠
''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
Comm1.PortOpen = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -