123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
-
- Option Explicit On
- Imports System.IO
- Imports System.Net.Sockets
- Public Class Form5
- Dim Listener As New TcpListener(8000)
- Dim Client As TcpClient
- Dim appPath As String = Application.StartupPath()
- Dim Newline As String
- Dim message As String
- Dim nStart As Integer
- Dim nLast As Integer
- Private IsFormBeingDragged As Boolean = False
- Private MouseDownX As Integer
- Private MouseDownY As Integer
- Dim z As String
- Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- For counter = 10 To 90 Step +20
- Me.Opacity = counter / 100
- Me.Refresh()
- Threading.Thread.Sleep(50)
- Next
- Me.Opacity = 100
- End Sub
- Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
- If e.Button = MouseButtons.Left Then
- IsFormBeingDragged = True
- MouseDownX = e.X
- MouseDownY = e.Y
- End If
- End Sub
- Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
- If e.Button = MouseButtons.Left Then
- IsFormBeingDragged = False
- End If
- End Sub
- Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
- If IsFormBeingDragged Then
- Dim temp As Point = New Point()
- temp.X = Me.Location.X + (e.X - MouseDownX)
- temp.Y = Me.Location.Y + (e.Y - MouseDownY)
- Me.Location = temp
- temp = Nothing
- End If
- End Sub
- Private Sub Form5_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
- Listener.Stop()
- End Sub
- Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Timer1.Start()
- Listener.Start()
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
-
- If Listener.Pending = True Then
- message = ""
- Client = Listener.AcceptTcpClient()
- Dim reader As New StreamReader(Client.GetStream())
- While reader.Peek <> -1
- message &= Convert.ToChar(reader.Read()).ToString
- End While
- Dim Newline As String
- Newline = System.Environment.NewLine
- If message.Contains("</>") Then
- nStart = InStr(message, "</>") + 4
- nLast = InStr(message, "<\>")
- message = Newline & "對方:" & Mid(message, nStart, nLast - nStart)
- End If
-
- End If
- TextBox1.Text += message
- TextBox1.SelectionStart = TextBox1.TextLength
- TextBox1.ScrollToCaret()
- message = ""
- End Sub
- Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
- Dim iCount As Integer
- For iCount = 90 To 10 Step -10
- Me.Opacity = iCount / 100
- Threading.Thread.Sleep(50)
- Next
- Me.Close()
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim client As TcpClient
- If TextBox3.Text = "" Then
- MsgBox("未設定對方IP地址")
- End If
- Try
- client = New TcpClient(TextBox3.Text, 8000)
- Dim writer As New StreamWriter(client.GetStream())
- writer.Write("</>" & " " & TextBox2.Text & "<\>")
- writer.Flush()
- Catch ex As Exception
- MsgBox(ex.Message & "對方啟動了嗎?")
- End Try
- Newline = System.Environment.NewLine
- TextBox1.Text += Newline & "本地:" & TextBox2.Text
- TextBox1.SelectionStart = TextBox1.TextLength
- TextBox1.ScrollToCaret()
- TextBox2.Text = ""
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
-
- End Sub
-
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End Sub
- Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End Sub
-
- Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
- End Sub
- Private Sub Button2_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Dim sb As New System.Text.StringBuilder
- Dim sfile As System.IO.FileStream
- If My.Computer.FileSystem.FileExists(appPath & "\聊天室對話" & ".txt") = False Then
- sfile = System.IO.File.Create(appPath & "\聊天室對話" & ".txt")
- sfile.Dispose()
- End If
- sb.AppendLine(TextBox1.Text)
- IO.File.WriteAllText((appPath & "\聊天室對話" & ".txt"), sb.ToString(), System.Text.Encoding.GetEncoding(950))
- MsgBox("對話已儲存")
- End Sub
- End Class
|