?? form1.vb
字號:
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports System.Threading
Imports System.String
Public Class Form1
Inherits System.Windows.Forms.Form
Dim socket As socket
Dim logined As Boolean = False
#Region " Windows 窗體設計器生成的代碼 "
Public Sub New()
MyBase.New()
'該調用是 Windows 窗體設計器所必需的。
InitializeComponent()
'在 InitializeComponent() 調用之后添加任何初始化
End Sub
'窗體重寫處置以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗體設計器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下過程是 Windows 窗體設計器所必需的
'可以使用 Windows 窗體設計器修改此過程。
'不要使用代碼編輯器修改它。
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents TxtIDOrder As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TxtPassword As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents BtExit As System.Windows.Forms.Button
Friend WithEvents BtLogin As System.Windows.Forms.Button
Friend WithEvents NotifyIcon1 As System.Windows.Forms.NotifyIcon
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.TxtIDOrder = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.TxtPassword = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.BtExit = New System.Windows.Forms.Button
Me.BtLogin = New System.Windows.Forms.Button
Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Timer1
'
Me.Timer1.Enabled = True
'
'TxtIDOrder
'
Me.TxtIDOrder.Location = New System.Drawing.Point(322, 168)
Me.TxtIDOrder.Name = "TxtIDOrder"
Me.TxtIDOrder.Size = New System.Drawing.Size(103, 21)
Me.TxtIDOrder.TabIndex = 35
Me.TxtIDOrder.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(206, 168)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(50, 32)
Me.Label3.TabIndex = 34
Me.Label3.Text = "編號:"
'
'TxtPassword
'
Me.TxtPassword.Location = New System.Drawing.Point(322, 240)
Me.TxtPassword.Name = "TxtPassword"
Me.TxtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TxtPassword.Size = New System.Drawing.Size(103, 21)
Me.TxtPassword.TabIndex = 33
Me.TxtPassword.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(206, 240)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(50, 24)
Me.Label2.TabIndex = 32
Me.Label2.Text = "密碼:"
'
'BtExit
'
Me.BtExit.Location = New System.Drawing.Point(350, 320)
Me.BtExit.Name = "BtExit"
Me.BtExit.Size = New System.Drawing.Size(68, 32)
Me.BtExit.TabIndex = 31
Me.BtExit.Text = "退出"
'
'BtLogin
'
Me.BtLogin.Location = New System.Drawing.Point(233, 320)
Me.BtLogin.Name = "BtLogin"
Me.BtLogin.Size = New System.Drawing.Size(62, 32)
Me.BtLogin.TabIndex = 30
Me.BtLogin.Text = "登錄"
'
'NotifyIcon1
'
Me.NotifyIcon1.Icon = CType(resources.GetObject("NotifyIcon1.Icon"), System.Drawing.Icon)
Me.NotifyIcon1.Text = "NotifyIcon1"
Me.NotifyIcon1.Visible = True
'
'Label1
'
Me.Label1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.ForeColor = System.Drawing.SystemColors.Highlight
Me.Label1.Location = New System.Drawing.Point(184, 72)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(320, 24)
Me.Label1.TabIndex = 36
Me.Label1.Text = " 服務器與客戶端通訊測試"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(678, 566)
Me.ControlBox = False
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TxtIDOrder)
Me.Controls.Add(Me.TxtPassword)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.BtExit)
Me.Controls.Add(Me.BtLogin)
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "用戶登錄"
Me.ResumeLayout(False)
End Sub
#End Region
Sub establistsocket(ByVal state As Object)
Dim serveradd As IPAddress = Dns.Resolve("61.174.73.45").AddressList(0)
Dim enpoint As New IPEndPoint(serveradd, 50)
Dim temp As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
temp.Blocking = True '設置Socket對象處于阻塞狀態
temp.Connect(enpoint) '連接服務器
socket = temp
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000)
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 5000)
If socket.Connected Then
Dim info As String
info = "L" & TxtIDOrder.Text.PadRight(6) & TxtPassword.Text.PadRight(10)
SendInfo(info) '發送登錄信息
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim ASCII As System.Text.Encoding = System.Text.Encoding.ASCII
Dim receivebyte(20) As Byte
Dim receivePage As String = String.Empty
If Not socket Is Nothing Then
If socket.Available <> 0 Then
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000)
Dim bytes As Int32 = socket.Receive(receivebyte, receivebyte.Length, 0) '接收二進制信息
receivePage = ASCII.GetString(receivebyte, 0, bytes) '轉換為字符
ProcessInfo(receivePage)
End If
End If
End Sub
Public Sub ProcessInfo(ByVal info As String)
Dim flag As String
flag = info.Substring(0, 2)
Select Case flag
Case "MM"
MsgBox(info.Substring(2, Len(info) - 2))
Case "L0"
MsgBox("編號或密碼輸入有誤,請重試!", MsgBoxStyle.Exclamation, Me.Text)
Case "L1"
MsgBox("恭喜你,登錄成功!")
Me.Hide()
Case "L2"
MsgBox("你的剩余機時小于0,登錄失敗!", MsgBoxStyle.Exclamation, Me.Text)
Case "E0"
MsgBox("編號或密碼輸入有誤,請重試!", MsgBoxStyle.Exclamation, Me.Text)
Case "E1"
MsgBox("恭喜你,退出成功!")
Me.Close()
Case "E2"
MsgBox("你的剩余機時小于0,請在下次上機前續機時,退出成功!", , Me.Text)
Me.Close()
End Select
End Sub
Private Sub BtLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtLogin.Click
If logined = True Then
Dim info As String
info = "L" & TxtIDOrder.Text.PadRight(6) & TxtPassword.Text.PadRight(10)
SendInfo(info)
Else
ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf establistsocket))
End If
End Sub
Function SendInfo(ByVal info As String)
Dim ASCII As System.Text.Encoding = System.Text.Encoding.ASCII
Dim byteSend As Byte()
byteSend = ASCII.GetBytes(info)
socket.Send(byteSend, byteSend.Length, 1)
End Function
Private Sub BtExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtExit.Click
Dim info As String
info = "E" & TxtIDOrder.Text.PadRight(6) & TxtPassword.Text.PadRight(10)
SendInfo(info)
End Sub
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.Show()
End Sub
Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -