I am making a User to User chat system. We have a server that a fair few users access remotely from different sites.
Because everyone's on the one PC with the same IP I made my program read and write to text files to store the chat logs and receive the messages. (Timer to read text file) So it may make this a bit harder :/
So everyone will be running this program from different users at once. So I want to be able to make a Notify Icon Balloon Tip pop up on a specified users computer. Is it possible?
So this is the cource code for my program. So it can show you's how it's done. It's pretty basic.
Because everyone's on the one PC with the same IP I made my program read and write to text files to store the chat logs and receive the messages. (Timer to read text file) So it may make this a bit harder :/
So everyone will be running this program from different users at once. So I want to be able to make a Notify Icon Balloon Tip pop up on a specified users computer. Is it possible?
So this is the cource code for my program. So it can show you's how it's done. It's pretty basic.
VB.NET:
Imports System.ComponentModel
Imports Microsoft.Win32
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FILE_NAME As String = "Z:\Sunland Messenger Chat Logs\" & System.Environment.UserName & ListBox1.SelectedItem & ".txt"
Dim FILE_NAME2 As String = "Z:\Sunland Messenger Chat Logs\" & ListBox1.SelectedItem & System.Environment.UserName & ".txt"
If ListBox1.SelectedIndex = -1 Then
MessageBox.Show("Please select a user to message first.")
Else
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
objWriter.Write(vbNewLine & System.Environment.UserName & " Says: " & TextBox1.Text)
objWriter.Close()
TextBox1.Clear()
ElseIf System.IO.File.Exists(FILE_NAME2) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME2, True)
objWriter.Write(vbNewLine & System.Environment.UserName & " Says: " & TextBox1.Text)
objWriter.Close()
TextBox1.Clear()
Else
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
objWriter.Write(System.Environment.UserName & " Says: " & TextBox1.Text)
objWriter.Close()
TextBox1.Clear()
End If
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
Try
Dim Valid As Integer = DirectCast(SubKey.GetValue("RunLogonScriptSync"), Integer)
Dim _Users As String = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
Dim _Username As String = System.IO.Path.GetFileNameWithoutExtension(_Users)
If _Users.ToLower.Contains("\users\") Then
If _Username = "Administrator" Then
Else
If _Username = "Toby" Then
ListBox1.Items.Add("Admin")
End If
ListBox1.Items.Add(_Username)
ListBox1.Items.Remove("Toby")
ListBox1.Items.Remove(System.Environment.UserName)
End If
End If
Catch ex As Exception
End Try
End Using
Next
NotifyIcon1.Visible = True
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
Me.WindowState = FormWindowState.Minimized
Me.Hide()
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Show()
Me.WindowState = FormWindowState.Normal
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
NotifyIcon1.Visible = False
Application.Exit()
End
End Sub
Private Sub ExitToolStripMenuItem1_Click_1(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem1.Click
NotifyIcon1.Visible = False
Application.Exit()
End
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
If ListBox1.SelectedIndex = -1 Then
Else
If File.Exists("Z:\Sunland Messenger Chat Logs\" & System.Environment.UserName & ListBox1.SelectedItem & ".txt") Then
Dim strFile As String = "Z:\Sunland Messenger Chat Logs\" & System.Environment.UserName & ListBox1.SelectedItem & ".txt"
Dim sr As New IO.StreamReader(strFile)
TextBox2.Text = sr.ReadToEnd()
sr.Close()
TextBox2.Select(TextBox2.TextLength, 0)
TextBox2.ScrollToCaret()
ElseIf File.Exists("Z:\Sunland Messenger Chat Logs\" & ListBox1.SelectedItem & System.Environment.UserName & ".txt") Then
Dim strFile As String = "Z:\Sunland Messenger Chat Logs\" & ListBox1.SelectedItem & System.Environment.UserName & ".txt"
Dim sr As New IO.StreamReader(strFile)
TextBox2.Text = sr.ReadToEnd()
sr.Close()
TextBox2.Select(TextBox2.TextLength, 0)
TextBox2.ScrollToCaret()
Else
TextBox2.Text = ""
End If
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Button1.PerformClick()
End If
End Sub
End Class