?? frmtalker.vb
字號:
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threading
Imports System.Net.Sockets
Imports System.Windows.Forms
Class frmTalker
Inherits Windows.Forms.Form
Private talkerObj As Talker
Public Sub New(ByVal talkerObj As Talker)
InitializeComponent()
Me.talkerObj = talkerObj '初始化talkerObj
AddHandler talkerObj.Notifications, _
AddressOf HandleTalkerNotifications
'添加事件
End Sub
Protected Overrides Sub OnClosed(ByVal e As EventArgs)
If Not (talkerObj Is Nothing) Then
RemoveHandler talkerObj.Notifications, _
AddressOf HandleTalkerNotifications
'停止事件
talkerObj.Dispose()
'關閉應用程序時釋放Talker對象
End If
MyBase.OnClosed(e)
End Sub
Private Sub HandleTalkerNotifications(ByVal notify As Talker.Notification, _
ByVal data As Object)
'處理TalkerObj的事件
Select Case notify
Case Talker.Notification.Initialized
Case Talker.Notification.StatusChange
' 狀態改變
Dim statusObj As Talker.Status = CType(data, Talker.Status)
Label1.Text = String.Format("目前狀態: {0}", statusObj)
'顯示狀態
If statusObj = Talker.Status.已正常連接 Then
TxtSend.Enabled = True
'連接上時,顯示文本框有效
TxtSend.Focus()
End If
Case Talker.Notification.ReceivedAppend
'響應獲取信息事件
TxtRe.AppendText(data.ToString())
Case Talker.Notification.ReceivedRefresh
TxtRe.Text = data.ToString()
TxtRe.SelectionStart = Int32.MaxValue
TxtRe.ScrollToCaret()
'響應更新
Case Talker.Notification.ErrorNotify
Close(data.ToString())
'響應錯誤
Case Talker.Notification.EndNotify
'停止事件
MessageBox.Show(Me, data.ToString(), "錯誤")
Close()
Case Else
Close()
End Select
End Sub
Private Overloads Sub Close(ByVal message As String)
MessageBox.Show(message, "錯誤!")
Close()
End Sub
#Region "初始化Windows.Form的代碼"
Friend WithEvents TxtSend As System.Windows.Forms.TextBox
Friend WithEvents TxtRe As System.Windows.Forms.TextBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Splitter1 = New System.Windows.Forms.Splitter()
Me.GroupBox2 = New System.Windows.Forms.GroupBox()
Me.TxtSend = New System.Windows.Forms.TextBox()
Me.TxtRe = New System.Windows.Forms.TextBox()
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.TxtRe})
Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Top
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(368, 112)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "接收信息"
'
'Label1
'
Me.Label1.Dock = System.Windows.Forms.DockStyle.Bottom
Me.Label1.Location = New System.Drawing.Point(0, 270)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(368, 23)
Me.Label1.TabIndex = 1
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Splitter1
'
Me.Splitter1.Dock = System.Windows.Forms.DockStyle.Top
Me.Splitter1.Location = New System.Drawing.Point(0, 112)
Me.Splitter1.Name = "Splitter1"
Me.Splitter1.Size = New System.Drawing.Size(368, 3)
Me.Splitter1.TabIndex = 2
Me.Splitter1.TabStop = False
'
'GroupBox2
'
Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.TxtSend})
Me.GroupBox2.Dock = System.Windows.Forms.DockStyle.Fill
Me.GroupBox2.Location = New System.Drawing.Point(0, 115)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(368, 155)
Me.GroupBox2.TabIndex = 3
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "發送信息"
'
'TxtSend
'
Me.TxtSend.Dock = System.Windows.Forms.DockStyle.Fill
Me.TxtSend.Enabled = False
Me.TxtSend.Location = New System.Drawing.Point(3, 17)
Me.TxtSend.Multiline = True
Me.TxtSend.Name = "TxtSend"
Me.TxtSend.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TxtSend.Size = New System.Drawing.Size(362, 135)
Me.TxtSend.TabIndex = 0
Me.TxtSend.Text = ""
'
'TxtRe
'
Me.TxtRe.BackColor = System.Drawing.SystemColors.Info
Me.TxtRe.Dock = System.Windows.Forms.DockStyle.Fill
Me.TxtRe.Location = New System.Drawing.Point(3, 17)
Me.TxtRe.Multiline = True
Me.TxtRe.Name = "TxtRe"
Me.TxtRe.ReadOnly = True
Me.TxtRe.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TxtRe.Size = New System.Drawing.Size(362, 92)
Me.TxtRe.TabIndex = 0
Me.TxtRe.Text = ""
'
'frmTalker
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(368, 293)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox2, Me.Splitter1, Me.Label1, Me.GroupBox1})
Me.Name = "frmTalker"
Me.Text = "點對點聊天"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub txtSend_KeyPress(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TxtSend.KeyPress
If e.KeyChar = Chr(13) Then
If Not (talkerObj Is Nothing) Then
talkerObj.SendTalk(CType(sender, TextBox).Text)
End If
End If
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -