Advertisement
TermSpar

Messenger Application

Oct 31st, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.92 KB | None | 0 0
  1. Option Explicit On
  2. Imports System.IO
  3. Imports System.Net.Sockets
  4. Imports System.Net
  5.  
  6. Public Class Form1
  7.     Dim Client As TcpClient
  8.     Dim Listener As New TcpListener(8000)
  9.     Dim Client2 As TcpClient
  10.     Private Sub _FormClosing() Handles Me.FormClosing
  11.         Listener.Stop()
  12.     End Sub
  13.     Private Sub _Load() Handles MyBase.Load
  14.         Timer2.Start()
  15.         Listener.Start()
  16.     End Sub
  17.     Private Sub _Tick() Handles Timer1.Tick
  18.         txtNick.Hide()
  19.         Dim Message As String
  20.         Dim nStart As Integer
  21.         Dim nLast As Integer
  22.  
  23.  
  24.  
  25.         If Listener.Pending = True Then
  26.             Message = ""
  27.             Client = Listener.AcceptTcpClient()
  28.             Dim Reader As New StreamReader(Client.GetStream())
  29.  
  30.             While Reader.Peek > -1
  31.                 Message &= Convert.ToChar(Reader.Read()).ToString
  32.             End While
  33.  
  34.             If Message.Contains("</>") Then
  35.                 nStart = InStr(Message, "</>") + 4
  36.                 nLast = InStr(Message, "<\>")
  37.                 Message = Mid(Message, nStart, nLast - nStart)
  38.             End If
  39.             TextBox2.AppendText(Message & vbNewLine)
  40.         End If
  41.     End Sub
  42.    
  43.  
  44.     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs)
  45.  
  46.  
  47.     End Sub
  48.  
  49.     Private Sub Button3_Click(sender As System.Object, e As System.EventArgs)
  50.         Me.ComboBox1.Items.AddRange(Dns.GetHostAddresses(GetComputerName))
  51.     End Sub
  52.  
  53.     Private Function GetComputerName() As String
  54.         Return Dns.GetHostName
  55.     End Function
  56.  
  57.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  58.         RichTextBox1.Hide()
  59.         Timer1.Start()
  60.        
  61.         Dim r As Rectangle
  62.         If Parent IsNot Nothing Then
  63.             r = Parent.RectangleToScreen(Parent.ClientRectangle)
  64.         Else
  65.             r = Screen.FromPoint(Me.Location).WorkingArea
  66.         End If
  67.  
  68.         Dim x = r.Left + (r.Width - Me.Width) \ 2
  69.         Dim y = r.Top + (r.Height - Me.Height) \ 2
  70.         Me.Location = New Point(x, y)
  71.  
  72.  
  73.         Me.ComboBox1.Items.AddRange(Dns.GetHostAddresses(GetComputerName))
  74.         Label8.Hide()
  75.         Dim myIPaddress As String
  76.         Dim tmpHostName As String = System.Net.Dns.GetHostName()
  77.         myIPaddress = System.Net.Dns.GetHostByName(tmpHostName).AddressList(0).ToString()
  78.         txtNick.Text = myIPaddress
  79.         Label11.Text = "Your local IP is " & txtNick.Text
  80.     End Sub
  81.  
  82.     Private Sub Button2_Click_1(sender As System.Object, e As System.EventArgs) Handles Button2.Click
  83.         Application.Exit()
  84.     End Sub
  85.  
  86.     Private Sub btnClick(sender As System.Object, e As System.EventArgs)
  87.  
  88.     End Sub
  89.  
  90.     Private Sub PictureBox2_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox2.Click
  91.         Dim Person As String
  92.         Person = ComboBox1.Text
  93.         Try
  94.             Client = New TcpClient(Person, 8000)
  95.             Dim Writer As New StreamWriter(Client.GetStream())
  96.             Writer.Write("</> " & TextBox1.Text & " -From " & txtNickname.Text & " (" & txtNick.Text & ")" & " at " & Label8.Text & " <\>")
  97.             Writer.Flush()
  98.         Catch ex As Exception
  99.             MsgBox(ex.Message)
  100.         End Try
  101.         If ComboBox1.Text = Nothing Then
  102.             MsgBox("Please Enter an IP To Recieve Your Message -Ben", MsgBoxStyle.Critical, "IPv4 Messenger Script Error")
  103.         End If
  104.         Me.Text = "IPv4 Messanger (Messaging: " & ComboBox1.Text & " as " & txtNick.Text & ")"
  105.         ListBox1.Items.Add(ComboBox1.Text)
  106.         Button1.PerformClick()
  107.        
  108.     End Sub
  109.    
  110.  
  111.     Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
  112.  
  113.     End Sub
  114.     Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
  115.         If e.KeyCode = Keys.Enter Then
  116.             Dim Person As String
  117.             Person = ComboBox1.Text
  118.             Try
  119.                 Client = New TcpClient(Person, 8000)
  120.                 Dim Writer As New StreamWriter(Client.GetStream())
  121.                 Writer.Write("</> " & TextBox1.Text & " -From " & txtNickname.Text & " (" & txtNick.Text & ")" & " at " & Label8.Text & " <\>")
  122.                 Writer.Flush()
  123.             Catch ex As Exception
  124.                 MsgBox(ex.Message)
  125.             End Try
  126.             ListBox1.Items.Add(ComboBox1.Text)
  127.             Button1.PerformClick()
  128.         End If
  129.         Me.Text = "IPv4 Messanger (Messaging: " & ComboBox1.Text & " as " & txtNick.Text & ")"
  130.     End Sub
  131.  
  132.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  133.         TextBox1.Clear()
  134.     End Sub
  135.  
  136.     Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
  137.         Label8.Text = Format(Now, "h:mm tt")
  138.     End Sub
  139.  
  140.     Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  141.         Application.Exit()
  142.     End Sub
  143.  
  144.     Private Sub Button3_Click_1(sender As System.Object, e As System.EventArgs) Handles Button3.Click
  145.         ListBox1.Items.Clear()
  146.     End Sub
  147.  
  148.     Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  149.  
  150.     End Sub
  151.  
  152.     Private Sub txtNick_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNick.TextChanged
  153.  
  154.     End Sub
  155.  
  156.     Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  157.  
  158.     End Sub
  159.  
  160.     Private Sub InfoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InfoToolStripMenuItem.Click
  161.         MsgBox("IPv4 Messanger uses a system of networking called TCP to send messages from one IPv4 address to another as long as they are on the same WiFi", MsgBoxStyle.Information)
  162.     End Sub
  163.  
  164.     Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
  165.         TextBox2.Clear()
  166.     End Sub
  167.  
  168.     Private Sub RedToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles RedToolStripMenuItem.Click
  169.         TextBox2.ForeColor = Color.Red
  170.         TextBox2.BackColor = Color.Gainsboro
  171.         TextBox1.BackColor = Color.White
  172.         TextBox1.ForeColor = Color.Black
  173.     End Sub
  174.  
  175.     Private Sub BlackToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles BlackToolStripMenuItem.Click
  176.         TextBox2.ForeColor = Color.Black
  177.         TextBox2.BackColor = Color.Gainsboro
  178.         TextBox1.BackColor = Color.White
  179.         TextBox1.ForeColor = Color.Black
  180.     End Sub
  181.  
  182.     Private Sub PinkToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PinkToolStripMenuItem.Click
  183.         TextBox2.ForeColor = Color.Violet
  184.         TextBox2.BackColor = Color.Gainsboro
  185.         TextBox1.BackColor = Color.White
  186.         TextBox1.ForeColor = Color.Black
  187.     End Sub
  188.  
  189.     Private Sub BlueToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles BlueToolStripMenuItem.Click
  190.         TextBox2.ForeColor = Color.Blue
  191.         TextBox2.BackColor = Color.Gainsboro
  192.         TextBox1.BackColor = Color.White
  193.         TextBox1.ForeColor = Color.Black
  194.     End Sub
  195.  
  196.     Private Sub LimeToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles LimeToolStripMenuItem.Click
  197.         TextBox2.ForeColor = Color.Green
  198.         TextBox1.BackColor = Color.White
  199.         TextBox1.ForeColor = Color.Black
  200.         TextBox2.BackColor = Color.Gainsboro
  201.     End Sub
  202.  
  203.     Private Sub H4X0RToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles H4X0RToolStripMenuItem.Click
  204.         TextBox2.ForeColor = Color.Lime
  205.         TextBox2.BackColor = Color.Black
  206.         TextBox1.BackColor = Color.Black
  207.         TextBox1.ForeColor = Color.Lime
  208.     End Sub
  209.  
  210.     Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick
  211.  
  212.     End Sub
  213.  
  214.     Private Sub Label8_Click(sender As System.Object, e As System.EventArgs) Handles Label8.Click
  215.  
  216.     End Sub
  217.  
  218.  
  219.     Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
  220.         If TextBox1.SelectedText <> "" Then
  221.             Clipboard.SetText(TextBox1.SelectedText)
  222.         Else
  223.             MsgBox("Please highlight the text that you would like to copy -Ben", MsgBoxStyle.Critical, "IPv4 Copying Error")
  224.         End If
  225.     End Sub
  226.  
  227.     Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
  228.         Dim iData As IDataObject = Clipboard.GetDataObject()
  229.         If iData.GetDataPresent(DataFormats.Text) Then
  230.             TextBox1.SelectedText = CType(iData.GetData(DataFormats.Text), String)
  231.         Else
  232.             MsgBox("No data was found in your ClipBoard -Ben", MsgBoxStyle.Critical, "IPv4 Pasting Error")
  233.         End If
  234.     End Sub
  235. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement