📄 frmclient.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "richtx32.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form frmClient
BorderStyle = 1 'Fixed Single
Caption = "聊天室_客户端"
ClientHeight = 5145
ClientLeft = 45
ClientTop = 330
ClientWidth = 5040
Icon = "frmclient.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5145
ScaleWidth = 5040
StartUpPosition = 1 'CenterOwner
Begin MSComDlg.CommonDialog CommonDialog1
Left = 2400
Top = 3000
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton cmdQuit
Caption = "断开"
Height = 375
Left = 3960
TabIndex = 11
Top = 4680
Width = 990
End
Begin VB.CommandButton cmdExit
Caption = "退出"
Height = 375
Left = 3960
TabIndex = 10
Top = 4200
Width = 990
End
Begin VB.CommandButton cmdLogin
Caption = "登录"
Height = 375
Left = 3840
TabIndex = 9
Top = 705
Width = 975
End
Begin RichTextLib.RichTextBox rtbIn
Height = 2295
Left = 75
TabIndex = 8
Top = 1560
Width = 4860
_ExtentX = 8573
_ExtentY = 4048
_Version = 393217
BackColor = 16777215
Enabled = -1 'True
ReadOnly = -1 'True
ScrollBars = 2
TextRTF = $"frmclient.frx":030A
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSComctlLib.Toolbar Toolbar1
Align = 1 'Align Top
Height = 660
Left = 0
TabIndex = 5
Top = 0
Width = 5040
_ExtentX = 8890
_ExtentY = 1164
ButtonWidth = 1032
ButtonHeight = 1005
Appearance = 1
ImageList = "ImageList1"
_Version = 393216
BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628}
NumButtons = 4
BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Login"
ImageKey = "login"
EndProperty
BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Connect"
ImageKey = "connect"
EndProperty
BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Save"
ImageKey = "save"
EndProperty
BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628}
Key = "Quit"
ImageKey = "quit"
EndProperty
EndProperty
End
Begin MSComctlLib.ImageList ImageList1
Left = 5520
Top = 3960
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 32
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 4
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmclient.frx":03A9
Key = "login"
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmclient.frx":06C5
Key = "connect"
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmclient.frx":09E1
Key = "save"
EndProperty
BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmclient.frx":0AF5
Key = "quit"
EndProperty
EndProperty
End
Begin VB.CommandButton cmdConnect
Caption = "连接"
Height = 375
Left = 3840
TabIndex = 4
Top = 1200
Width = 975
End
Begin VB.TextBox txtPort
BackColor = &H00FFFFFF&
Height = 450
Left = 960
Locked = -1 'True
TabIndex = 3
Top = 1125
Width = 2655
End
Begin VB.TextBox txtHost
BackColor = &H00FFFFFF&
Height = 390
Left = 945
Locked = -1 'True
TabIndex = 2
Top = 720
Width = 2670
End
Begin VB.TextBox txtOut
Height = 855
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 4200
Width = 3795
End
Begin MSWinsockLib.Winsock tcpClient
Left = 3600
Top = 3120
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.Label Label3
BackColor = &H00FF0000&
BackStyle = 0 'Transparent
Caption = "端口"
ForeColor = &H00000000&
Height = 255
Left = 240
TabIndex = 7
Top = 1200
Width = 570
End
Begin VB.Label Label2
BackColor = &H00FF0000&
BackStyle = 0 'Transparent
Caption = "输入要发送的消息"
ForeColor = &H00000000&
Height = 255
Left = 105
TabIndex = 6
Top = 3960
Width = 1665
End
Begin VB.Label lblName
BackColor = &H00FF0000&
BackStyle = 0 'Transparent
Caption = "登录IP"
ForeColor = &H00000000&
Height = 240
Left = 240
TabIndex = 1
Top = 840
Width = 615
End
End
Attribute VB_Name = "frmClient"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim NewClient As Boolean
Private Sub cmdConnect_Click() '连接到服务器端
On Error GoTo errhandle: '连接出现错误,跳转,通过系统弹出个对话框提示
tcpClient.RemoteHost = txtHost.Text '连接服务器IP
tcpClient.RemotePort = txtPort.Text '连接服务器端口
tcpClient.Connect '连接建立
NewClient = True '设置标志变量
Exit Sub
errhandle: '错误处理
MsgBox Err.Description '出现错误时弹出对话框
End Sub
Private Sub cmdExit_Click() '退出程序
response = MsgBox("真的要退出吗?", vbYesNo, "退出")
If response = vbYes Then
Unload frmClient
Else
frmClient.Show
End If
End Sub
Private Sub cmdLogin_Click() '登录服务器IP地址和端口
Load frmClientLogIn '调用client表单处理
frmClientLogIn.Show
End Sub
Private Sub cmdQuit_Click() '断开连接
On Error GoTo errhandle:
tcpClient.SendData "退出" & lblName.Caption & CStr(Now()) '发送中断连接的请求
Exit Sub
errhandle:
MsgBox Err.Description
End Sub
Private Sub Form_Load() '系统初始化
Me.cmdConnect.Enabled = False '当没有连接到服务器端时,连接按钮和断开按钮无效
Me.cmdQuit.Enabled = False
End Sub
Private Sub tcpClient_Connect() '请求建立TCP连接
txtOut.Locked = False
tcpClient.SendData "/" + lblName.Caption
End Sub
Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
Dim sData As String
If NewClient Then
MsgBox "连接成功!"
NewClient = False
End If
tcpClient.GetData sData
rtbIn.Text = rtbIn.Text + sData '添加信息到文本框中
rtbIn.SelStart = Len(sData)
If sData = "you can quit." Then '判断是否为中断连接信息
tcpClient.Close '中断连接
End If
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case Is = "Connect"
cmdConnect_Click
Case Is = "Login"
cmdLogin_Click
Case Is = "Quit"
cmdQuit_Click
Case Is = "Save"
cmdSave_click
End Select
End Sub
Private Sub cmdSave_click() '保存菜单操作
CommonDialog1.ShowSave
rtbIn.SaveFile (CommonDialog1.FileName)
End Sub
Private Sub txtOut_KeyUp(KeyCode As Integer, Shift As Integer) '发送消息
On Error GoTo errhandle: '发生错误是跳转
If KeyCode = 13 Then '按下回车键即可发送
tcpClient.SendData lblName.Caption + "说:" + txtOut.Text '显示发送消息+发送人昵称
'rtbIn.Text = rtbIn.Text + txtOut.Text
txtOut.Text = ""
End If
Exit Sub
errhandle: '错误处理
MsgBox Err.Description
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -