📄 form2.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form2
Caption = "Form2"
ClientHeight = 5670
ClientLeft = 60
ClientTop = 345
ClientWidth = 6540
LinkTopic = "Form2"
MaxButton = 0 'False
ScaleHeight = 5670
ScaleWidth = 6540
StartUpPosition = 3 '窗口缺省
Begin MSWinsockLib.Winsock Winsock1
Left = 5880
Top = 360
_ExtentX = 741
_ExtentY = 741
_Version = 393216
Protocol = 1
End
Begin VB.TextBox Text1
Height = 270
Left = 1080
Locked = -1 'True
TabIndex = 6
Top = 480
Width = 1575
End
Begin VB.TextBox Text2
Height = 270
Left = 4080
Locked = -1 'True
TabIndex = 5
Top = 480
Width = 1695
End
Begin VB.Frame Frame1
Caption = "聊天记录"
Height = 2895
Left = 0
TabIndex = 3
Top = 840
Width = 6135
Begin VB.TextBox Text4
Height = 2535
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 4
Top = 240
Width = 6015
End
End
Begin VB.Frame Frame2
Caption = "发送"
Height = 1215
Left = 0
TabIndex = 1
Top = 3840
Width = 6135
Begin VB.TextBox Text5
Height = 735
Left = 240
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 2
Top = 240
Width = 5895
End
End
Begin VB.CommandButton Command2
Caption = "发送"
Height = 375
Left = 2760
TabIndex = 0
Top = 5160
Width = 735
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "本机IP地址:"
Height = 255
Left = 0
TabIndex = 12
Top = 120
Width = 1095
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "Label2"
Height = 255
Left = 1200
TabIndex = 11
Top = 120
Width = 1695
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "本机端口:"
Height = 255
Left = 120
TabIndex = 10
Top = 480
Width = 975
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "远程端口:"
Height = 255
Left = 3000
TabIndex = 9
Top = 480
Width = 1095
End
Begin VB.Label Label6
BackStyle = 0 'Transparent
Caption = "本机名:"
Height = 255
Left = 3120
TabIndex = 8
Top = 120
Width = 855
End
Begin VB.Label Label7
BackStyle = 0 'Transparent
Caption = "Label7"
Height = 255
Left = 4080
TabIndex = 7
Top = 120
Width = 1575
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command2_Click()
On Error GoTo ErrorPro
Dim s As String
s = xingming + Text5.Text
Winsock1.SendData s
Text4.Text = Text4.Text + Chr$(13) + Chr$(10) + "我说:" + Text5.Text
Text5.Text = ""
Exit Sub
ErrorPro:
MsgBox "网络出错,请重新连接!"
End
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim ss As String
Dim s1 As String
Dim s2 As String
Dim melocalport As String
Dim tlocalport As String
Label2.Caption = Winsock1.LocalIP
Label7.Caption = Winsock1.LocalHostName
'求本地端口
i = Len(Trim(Label2.Caption))
For j = i To j - 3 Step -1
ss = Mid(Trim(Label2.Caption), j, 1)
If ss <> "." Then
s1 = ss + s1
Else
Exit For
End If
Next j
melocalport = 1000 + Val(s1)
Text1.Text = Trim(Str(melocalport))
'求远程端口
i = Len(Trim(ipname))
For j = i To j - 3 Step -1
ss = Mid(Trim(ipname), j, 1)
If ss <> "." Then
s2 = ss + s2
Else
Exit For
End If
Next j
tlocalport = 1000 + Val(s2)
Text2.Text = Trim(Str(tlocalport))
Text4.Text = Left(Trim(xingming), Trim(Len(xingming) - 2)) + "-----" + "welcome!"
'联系
Winsock1.LocalPort = Text1.Text
Winsock1.RemotePort = Text2.Text
Winsock1.RemoteHost = ipname
Winsock1.Bind Text1.Text
form1k = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
form1k = False
End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
On Error GoTo ErrorPro
Dim s As String
s = xingming + Text5.Text
Winsock1.SendData s
Text4.Text = Text4.Text + Chr$(13) + Chr$(10) + "我说:" + Text5.Text
Text5.Text = ""
Exit Sub
ErrorPro:
MsgBox "网络出错,请重新连接!"
End
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
On Error GoTo ErrorPro
Dim receviedata As String
Winsock1.GetData receviedata
Text4.Text = Text4.Text + Chr$(13) + Chr$(10) + receviedata
Exit Sub
ErrorPro:
MsgBox "网络出错,请重新连接!"
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -