⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 客户端.frm

📁 网络棋牌游戏(可作为本科生课程设计使用)
💻 FRM
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1 
   Caption         =   "聊天室客户端"
   ClientHeight    =   6045
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   7830
   LinkTopic       =   "Form1"
   ScaleHeight     =   6045
   ScaleWidth      =   7830
   StartUpPosition =   3  '窗口缺省
   Begin VB.CheckBox Check1 
      Caption         =   "悄悄话"
      Height          =   375
      Left            =   6600
      TabIndex        =   9
      Top             =   3720
      Width           =   975
   End
   Begin VB.ListBox List1 
      Height          =   4560
      Left            =   120
      TabIndex        =   5
      Top             =   480
      Width           =   1335
   End
   Begin VB.TextBox Text2 
      Height          =   3135
      Left            =   1680
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   4
      Top             =   480
      Width           =   5895
   End
   Begin VB.TextBox Text1 
      Height          =   975
      Left            =   1680
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   3
      Top             =   4080
      Width           =   5895
   End
   Begin VB.CommandButton Command3 
      Caption         =   "发送"
      Height          =   495
      Left            =   5520
      TabIndex        =   2
      Top             =   5280
      Width           =   855
   End
   Begin VB.CommandButton Command2 
      Caption         =   "断开"
      Height          =   495
      Left            =   3360
      TabIndex        =   1
      Top             =   5280
      Width           =   855
   End
   Begin VB.CommandButton Command1 
      Caption         =   "连接"
      Height          =   495
      Left            =   1080
      TabIndex        =   0
      Top             =   5280
      Width           =   855
   End
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   7320
      Top             =   5400
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.Label Label3 
      Caption         =   "对所有客户说:"
      Height          =   255
      Left            =   1680
      TabIndex        =   8
      Top             =   3840
      Width           =   1815
   End
   Begin VB.Label Label2 
      Caption         =   "聊天内容:"
      Height          =   255
      Left            =   1800
      TabIndex        =   7
      Top             =   240
      Width           =   4695
   End
   Begin VB.Label Label1 
      Caption         =   "现在人数:"
      Height          =   255
      Left            =   120
      TabIndex        =   6
      Top             =   240
      Width           =   1455
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
  Dim name1 As String
  Dim liststr As String
  Dim listflag As Integer
  Dim ch As String
  Dim nummax As Integer
  
  Private Sub Command1_Click()
  
    Winsock1.LocalPort = 0          '自动产生本地端口
    Winsock1.Connect InputBox("请输入服务器主机地址", "主机地址", "127.0.0.1")
  DoEvents
    name1 = InputBox("请输入你的姓名:", "姓名", "")
    Winsock1.SendData "1" & name1
    Command2.Enabled = True
    Command3.Enabled = True
    Form1.Caption = "聊天室客户端: " + name1
  End Sub
    
  Private Sub Command2_Click()
    Winsock1.SendData "3"      '3代表关闭  通知服务器端关闭连接
    DoEvents
    Winsock1.Close
    Command2.Enabled = False
    Command1.Enabled = True
    Command3.Enabled = False
    List1.Clear
    nummax = 0
  End Sub
    
  Private Sub Command3_Click()
    
    If Check1.Value = 1 Then
      If listflag = 1 Then       'check.value=1表示悄悄话被选,listflag=1表示悄悄话对象被选,这时发送悄悄话
        Winsock1.SendData Chr(2) + ch + Text1.Text
      Else
        MsgBox "你还没有选择要悄悄话的客户" + vbNewLine + "请你选择之后再发送悄悄话!", vbInformation, "提示"
      End If
    Else
      Winsock1.SendData "2" & Text1.Text   '2 代表对所有用户发送消息
    End If
  Text1.Text = ""
  End Sub

Private Sub Form_Load()
    Winsock1.RemotePort = 3128            '设定与Server端做Listen的Port相同
    
    Command2.Enabled = False
    Command3.Enabled = False
    listflag = 0
    nummax = 0
End Sub
    
Private Sub Form_Unload(Cancel As Integer)
  If Winsock1.State <> sckClosed Then
        Winsock1.SendData "3"
        DoEvents
        Winsock1.Close
        Winsock1.LocalPort = 0
  End If
End Sub
    
Private Sub List1_Click()
  listflag = 1
  liststr = List1.List(List1.ListIndex)
  ch = Mid(liststr, 2, 1)
End Sub

Private Sub Winsock1_Connect()
  If Winsock1.State = sckConnected Then
        Text2.Text = "已经连接上   本地端口 =" + Str(Winsock1.LocalPort) + "   远程端口 =   " + Str(Winsock1.RemotePort) + vbNewLine
        Command1.Enabled = False
  End If
    
End Sub
    
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  Dim mydata     As String
  Dim ch As String
  Dim length As Integer
  Dim strdata As String
  
  Winsock1.GetData mydata, vbString
  length = Len(mydata)
  ch = Mid(mydata, 1, 1)
  strdata = Mid(mydata, 2, length)
  If ch = Chr(3) Then
     List1.AddItem strdata
     nummax = nummax + 1
     Label1.Caption = "现在人数:" + Str(nummax)
  Else
     Text2.Text = Text2.Text + Mid(mydata, 3, Len(mydata) - 1) + vbNewLine
  End If
  Text1.SetFocus  '响应提示
  Text2.SelStart = Len(Text2.Text)  'textbox控制它的滚动条一直都在最下面
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  Text2.Text = Text2.Text + Description + vbNewLine
End Sub
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -