ChatClient
ChatClient is a Windows application. When ChatClient.exe is run, it first shows the splash screen that introduces the developer. When the user clicks connect, the application tries to the connect to server and when connected populates the list box with the current users online.
There is an EventClass class that derives from the abstract class and has delegates that are wrapped by ChatClient. Whenever EventClass receives message, it raises an event and ChatClient accordingly takes the necessary action.
ChatClient
/***************************************************************/
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Label lblErrorMessage;
private System.Windows.Forms.GroupBox grpClientChatBox;
private System.Windows.Forms.RichTextBox txtMessage;
private System.Windows.Forms.Label lblUserList;
private System.Windows.Forms.StatusBar stsConnected;
private System.Windows.Forms.Label lblUserName;
private System.Windows.Forms.TextBox txtUserName;
private System.Windows.Forms.ListBox lstUsers;
private System.Windows.Forms.Button btnConnect;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.GroupBox grpAuthenticate;
private System.Windows.Forms.TextBox txtProxyPassword;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.TextBox txtProxyUserName;
private System.Windows.Forms.Label lblUser;
#region MyVariables
private IMediator im = null;
private EventsClass em = null;
private ArrayList clientList = null;
private System.Windows.Forms.Button btnSend;
private System.Windows.Forms.TextBox txtSendMessage;
private System.Windows.Forms.GroupBox grpSend;
private System.Windows.Forms.Label lblUserCount;
private IClientImplement iciClient = null;
private Hashtable hsPrivateWindows = new Hashtable();
private string httpServerUrl =
ConfigurationSettings.AppSettings["HttpServerURL"].ToString();
private string tcpServerUrl =
ConfigurationSettings.AppSettings["TcpServerURL"].ToString();
#endregion
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
// InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(typeof(Form1));
this.lblErrorMessage = new System.Windows.Forms.Label();
this.grpClientChatBox = new System.Windows.Forms.GroupBox();
this.grpSend = new System.Windows.Forms.GroupBox();
this.lblUserCount = new System.Windows.Forms.Label();
this.btnSend = new System.Windows.Forms.Button();
this.txtSendMessage = new System.Windows.Forms.TextBox();
this.txtMessage = new System.Windows.Forms.RichTextBox();
this.lblUserList = new System.Windows.Forms.Label();
this.stsConnected = new System.Windows.Forms.StatusBar();
this.lblUserName = new System.Windows.Forms.Label();
this.txtUserName = new System.Windows.Forms.TextBox();
this.lstUsers = new System.Windows.Forms.ListBox();
this.btnConnect = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.grpAuthenticate = new System.Windows.Forms.GroupBox();
this.txtProxyPassword = new System.Windows.Forms.TextBox();
this.lblPassword = new System.Windows.Forms.Label();
this.txtProxyUserName = new System.Windows.Forms.TextBox();
this.lblUser = new System.Windows.Forms.Label();
this.grpClientChatBox.SuspendLayout();
this.grpSend.SuspendLayout();
this.groupBox1.SuspendLayout();
this.grpAuthenticate.SuspendLayout();
this.SuspendLayout();
//
// lblErrorMessage
//
this.lblErrorMessage.ForeColor = System.Drawing.Color.Red;
this.lblErrorMessage.Location =
new System.Drawing.Point(74, -112);
this.lblErrorMessage.Name = "lblErrorMessage";
this.lblErrorMessage.Size = new System.Drawing.Size(408, 88);
this.lblErrorMessage.TabIndex = 10;
//
// grpClientChatBox
//
this.grpClientChatBox.Controls.Add(this.grpSend);
this.grpClientChatBox.Controls.Add(this.txtMessage);
this.grpClientChatBox.Controls.Add(this.lblUserList);
this.grpClientChatBox.Controls.Add(this.stsConnected);
this.grpClientChatBox.Controls.Add(this.lblUserName);
this.grpClientChatBox.Controls.Add(this.txtUserName);
this.grpClientChatBox.Controls.Add(this.lstUsers);
this.grpClientChatBox.Controls.Add(this.btnConnect);
this.grpClientChatBox.Location =
new System.Drawing.Point(8, 104);
this.grpClientChatBox.Name = "grpClientChatBox";
this.grpClientChatBox.Size = new System.Drawing.Size(656, 408);
this.grpClientChatBox.TabIndex = 8;
this.grpClientChatBox.TabStop = false;
this.grpClientChatBox.Text = "Client";
//
// grpSend
//
this.grpSend.Controls.Add(this.lblUserCount);
this.grpSend.Controls.Add(this.btnSend);
this.grpSend.Controls.Add(this.txtSendMessage);
this.grpSend.Enabled = false;
this.grpSend.Location = new System.Drawing.Point(16, 200);
this.grpSend.Name = "grpSend";
this.grpSend.Size = new System.Drawing.Size(368, 120);
this.grpSend.TabIndex = 11;
this.grpSend.TabStop = false;
this.grpSend.Text = "Send";
//
// lblUserCount
//
this.lblUserCount.Location = new System.Drawing.Point(16, 88);
this.lblUserCount.Name = "lblUserCount";
this.lblUserCount.Size = new System.Drawing.Size(344, 23);
this.lblUserCount.TabIndex = 13;
//
// btnSend
//
this.btnSend.Font =
new System.Drawing.Font("Microsoft Sans Serif", 11F,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.btnSend.Location = new System.Drawing.Point(284, 24);
this.btnSend.Name = "btnSend";
this.btnSend.Size = new System.Drawing.Size(72, 48);
this.btnSend.TabIndex = 5;
this.btnSend.Text = "Send";
this.btnSend.Click +=
new System.EventHandler(this.btnSend_Click);
//
// txtSendMessage
//
this.txtSendMessage.ForeColor = System.Drawing.Color.Maroon;
this.txtSendMessage.Location = new System.Drawing.Point(8, 24);
this.txtSendMessage.Multiline = true;
this.txtSendMessage.Name = "txtSendMessage";
this.txtSendMessage.Size = new System.Drawing.Size(272, 48);
this.txtSendMessage.TabIndex = 4;
this.txtSendMessage.Text = "Hi!!";
this.txtSendMessage.KeyDown +=
new System.Windows.Forms.KeyEventHandler
(this.txtSendMessage_KeyDown);
//
// txtMessage
//
this.txtMessage.Location = new System.Drawing.Point(16, 56);
this.txtMessage.Name = "txtMessage";
this.txtMessage.ReadOnly = true;
this.txtMessage.Size = new System.Drawing.Size(360, 128);
this.txtMessage.TabIndex = 10;
this.txtMessage.Text = "
/*********************WELCOME TO CHAT ROOM ********************/";
//
// lblUserList
//
this.lblUserList.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblUserList.Font =
new System.Drawing.Font("Microsoft Sans Serif", 11.25F,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.lblUserList.Location = new System.Drawing.Point(480, 24);
this.lblUserList.Name = "lblUserList";
this.lblUserList.Size = new System.Drawing.Size(80, 32);
this.lblUserList.TabIndex = 9;
this.lblUserList.Text = "Users list";
this.lblUserList.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// stsConnected
//
this.stsConnected.Location = new System.Drawing.Point(3, 383);
this.stsConnected.Name = "stsConnected";
this.stsConnected.Size = new System.Drawing.Size(650, 22);
this.stsConnected.TabIndex = 8;
this.stsConnected.Text = "Not connected...";
//
// lblUserName
//
this.lblUserName.Location = new System.Drawing.Point(16, 24);
this.lblUserName.Name = "lblUserName";
this.lblUserName.Size = new System.Drawing.Size(64, 16);
this.lblUserName.TabIndex = 5;
this.lblUserName.Text = "UserName: ";
//
// txtUserName
//
this.txtUserName.Location = new System.Drawing.Point(96, 24);
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(192, 20);
this.txtUserName.TabIndex = 2;
this.txtUserName.Text = "User";
//
// lstUsers
//
this.lstUsers.Location = new System.Drawing.Point(424, 64);
this.lstUsers.Name = "lstUsers";
this.lstUsers.Size = new System.Drawing.Size(208, 303);
this.lstUsers.TabIndex = 4;
this.lstUsers.DoubleClick +=
new System.EventHandler(this.lstUsers_DoubleClick);
//
// btnConnect
//
this.btnConnect.Location = new System.Drawing.Point(304, 24);
this.btnConnect.Name = "btnConnect";
this.btnConnect.TabIndex = 3;
this.btnConnect.Text = "Connect";
this.btnConnect.Click +=
new System.EventHandler(this.btnConnect_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(-190, -120);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(248, 96);
this.groupBox1.TabIndex = 9;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Proxy authentication";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(128, 56);
this.textBox1.Name = "textBox1";
this.textBox1.PasswordChar = '*';
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 56);
this.label1.Name = "label1";
this.label1.TabIndex = 2;
this.label1.Text = "Password:";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(128, 24);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "ProxyUser";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 24);
this.label2.Name = "label2";
this.label2.TabIndex = 0;
this.label2.Text = "UserName:";
//
// label3
//
this.label3.ForeColor = System.Drawing.Color.Red;
this.label3.Location = new System.Drawing.Point(268, 16);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(396, 80);
this.label3.TabIndex = 12;
//
// grpAuthenticate
//
this.grpAuthenticate.Controls.Add(this.txtProxyPassword);
this.grpAuthenticate.Controls.Add(this.lblPassword);
this.grpAuthenticate.Controls.Add(this.txtProxyUserName);
this.grpAuthenticate.Controls.Add(this.lblUser);
this.grpAuthenticate.Enabled = false;
this.grpAuthenticate.Location = new System.Drawing.Point(4, 8);
this.grpAuthenticate.Name = "grpAuthenticate";
this.grpAuthenticate.Size = new System.Drawing.Size(248, 88);
this.grpAuthenticate.TabIndex = 11;
this.grpAuthenticate.TabStop = false;
this.grpAuthenticate.Text = "Proxy authentication";
//
// txtProxyPassword
//
this.txtProxyPassword.Location = new System.Drawing.Point(128, 56);
this.txtProxyPassword.Name = "txtProxyPassword";
this.txtProxyPassword.PasswordChar = '*';
this.txtProxyPassword.TabIndex = 1;
this.txtProxyPassword.Text = "password";
//
// lblPassword
//
this.lblPassword.Location = new System.Drawing.Point(16, 56);
this.lblPassword.Name = "lblPassword";
this.lblPassword.TabIndex = 2;
this.lblPassword.Text = "Password:";
//
// txtProxyUserName
//
this.txtProxyUserName.Location =
new System.Drawing.Point(128, 24);
this.txtProxyUserName.Name = "txtProxyUserName";
this.txtProxyUserName.TabIndex = 0;
this.txtProxyUserName.Text = "user";
//
// lblUser
//
this.lblUser.Location = new System.Drawing.Point(16, 24);
this.lblUser.Name = "lblUser";
this.lblUser.TabIndex = 0;
this.lblUser.Text = "UserName:";
//
// Form1
//
this.AcceptButton = this.btnSend;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor =
System.Drawing.Color.FromArgb(((System.Byte)(192)),
((System.Byte)(192)),
((System.Byte)(255)));
this.ClientSize = new System.Drawing.Size(680, 525);
this.Controls.Add(this.label3);
this.Controls.Add(this.grpAuthenticate);
this.Controls.Add(this.lblErrorMessage);
this.Controls.Add(this.grpClientChatBox);
this.Controls.Add(this.groupBox1);
this.Icon =
((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Form1";
this.Closing +=
new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
this.grpClientChatBox.ResumeLayout(false);
this.grpSend.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.grpAuthenticate.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private bool StartHttpServer()
{
bool result = false;
IDictionary id = null;
string uname = txtProxyUserName.Text;
string pwd = txtProxyPassword.Text;
ICredentials ic = null;
try
{
SoapClientFormatterSinkProvider scl =
new SoapClientFormatterSinkProvider();
SoapServerFormatterSinkProvider ssr =
new SoapServerFormatterSinkProvider();
ssr.TypeFilterLevel = TypeFilterLevel.Full;
IWebProxy proxy =
new WebProxy("proxy.sharda.mahindrabt.com", 80);
ic = new NetworkCredential(uname, pwd);
proxy.Credentials = ic;
id = new Hashtable();
id["port"] = 0;
id["typeFilterLevel"] = TypeFilterLevel.Full;
id["name"] = System.Guid.NewGuid().ToString();
HttpChannel htc = new HttpChannel(id, scl, ssr);
ChannelServices.RegisterChannel(htc);
this.SetChannelProxy(htc, proxy);
this.im = (IMediator) Activator.GetObject(typeof
(IMediator), this.httpServerUrl);
result = true;
}
catch (RemotingException ex)
{
MessageBox.Show(ex.Message + " Stact trace: " +
ex.StackTrace);
}
finally
{
}
return result;
}
private void SetChannelProxy( HttpChannel channel, IWebProxy proxy )
{
//get the channel data
FieldInfo clientChannelFieldInfo =
typeof(HttpChannel).GetField("_clientChannel",
BindingFlags.Instance |
BindingFlags.NonPublic);
//cast it to httpclientchannel to get an access to
//IWebProxy Class.
HttpClientChannel clientChannel =
(HttpClientChannel) clientChannelFieldInfo.GetValue(channel);
//get Proxy object
FieldInfo proxyObjectFieldInfo =
typeof(HttpClientChannel).GetField("_proxyObject",
BindingFlags.Instance |
BindingFlags.NonPublic);
//set up proxy explicitly.
proxyObjectFieldInfo.SetValue(clientChannel, proxy );
}
private bool StartTcpServer()
{
bool result = false;
try
{
BinaryClientFormatterSinkProvider bcfs =
new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider bsfs =
new BinaryServerFormatterSinkProvider();
bsfs.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary id = new Hashtable();
id = new Hashtable();
id["port"] = 0;
id["typeFilterLevel"] = TypeFilterLevel.Full;
id["name"] = System.Guid.NewGuid().ToString();
TcpChannel tcc = new TcpChannel(id, bcfs, bsfs);
ChannelServices.RegisterChannel(tcc);
this.im = (IMediator) Activator.GetObject(typeof(IMediator),
this.tcpServerUrl);
result = true;
}
catch (RemotingException ex)
{
MessageBox.Show(ex.Message + " Stact trace: " +
ex.StackTrace);
}
finally
{
}
return result;
}
private void btnConnect_Click(object sender, System.EventArgs e)
{
// StartHttpServer();
if (txtUserName.Text.CompareTo(string.Empty) == 0)
{
MessageBox.Show("Please enter user name.");
}
else
{
StartTcpServer();
if (this.im != null)
{
this.em = new EventsClass();
this.em.UserName = this.txtUserName.Text;
this.em.Message = "Hi!! I'm joining chat..";
this.em.ClientListHandler +=
new GetClientsList(this.em_ClientListHandler);
this.em.WelComeHandler +=
new WelComeMessage(this.em_WelComeHandler);
this.em.GetMessageFromOthersHandler +=
new GetMessageFromOthers
(this.em_GetMessageFromOthersHandler);
this.em.UserLeftHandler +=
new UserLeftChat(this.em_UserLeftHandler);
try
{
this.im.ConnectToChat(em);
this.btnConnect.Enabled = false;
this.stsConnected.Text = em.UserName +
" successfully connected.";
this.Text = em.UserName;
this.grpSend.Enabled = true;
this.txtUserName.Enabled = false;
this.txtMessage.BackColor = Color.LightCyan;
this.txtSendMessage.BackColor = Color.LightYellow;
this.grpClientChatBox.BackColor = Color.LightSkyBlue;
}
catch (RemotingException ex)
{
this.lblErrorMessage.Text = ex.Message;
MessageBox.Show("Exception occured. " + ex.Message);
this.ReleaseHandlers();
}
catch (System.Net.Sockets.SocketException socEx)
{
this.lblErrorMessage.Text = socEx.Message;
MessageBox.Show("Exception occured. " + socEx.Message);
this.ReleaseHandlers();
}
catch (Exception ex)
{
this.lblErrorMessage.Text = ex.Message;
MessageBox.Show("Exception occured. " + ex.Message);
this.ReleaseHandlers();
}
}
}
}
private void ReleaseHandlers()
{
try
{
this.em.ClientListHandler -=
new GetClientsList(this.em_ClientListHandler);
this.em.WelComeHandler -=
new WelComeMessage(this.em_WelComeHandler);
this.em.GetMessageFromOthersHandler -=
new GetMessageFromOthers
(this.em_GetMessageFromOthersHandler);
this.em.UserLeftHandler -=
new UserLeftChat(this.em_UserLeftHandler);
}
catch (Exception ex)
{
MessageBox.Show("No handlers to release. Error: " +
ex.Message);
}
}
public void em_ClientListHandler(IClientImplement ici)
{
this.clientList = ici.ClientList;
Thread th = new Thread(new ThreadStart(this.GetClientList));
th.Start();
}
private void GetClientList()
{
this.lstUsers.Items.Clear();
foreach (IClientImplement icc in this.clientList)
{
this.lstUsers.Items.Add(icc.UserName);
}
this.lstUsers.BackColor = Color.LightBlue;
this.lblUserCount.Text =
"There are currently " + this.clientList.Count.ToString() +
" users connected.";
}
public void em_WelComeHandler(IClientImplement ici)
{
this.iciClient = ici;
Thread th = new Thread(new ThreadStart(this.NewUserJoined));
th.Start();
}
private void NewUserJoined()
{
this.txtMessage.AppendText(Environment.NewLine);
this.txtMessage.AppendText(this.iciClient.UserName +
" joined chat at: " + DateTime.Now.ToString());
}
private void btnSend_Click(object sender, System.EventArgs e)
{
Thread th = new Thread(new ThreadStart(this.SendMessage));
th.Start();
}
private void SendMessage()
{
if (this.txtSendMessage.Text.CompareTo(string.Empty) != 0)
{
this.em.Message = txtSendMessage.Text.Trim();
em.ReceiverName = "ALL";
this.im.SendMessageToAll(em);
this.txtSendMessage.Text = string.Empty;
}
}
public void em_GetMessageFromOthersHandler(IClientImplement ici)
{
bool isAdded = false;
this.iciClient = ici;
Thread th =
new Thread(new ThreadStart(this.GetMessageFromOtherClients));
th.Start();
IDictionaryEnumerator ide =
this.hsPrivateWindows.GetEnumerator();
while (ide.MoveNext())
{
if (ide.Key.ToString().CompareTo
(this.iciClient.UserName) == 0)
{
isAdded = true;
}
}
if (!isAdded)
{
if (this.iciClient.ReceiverName.CompareTo
(this.txtUserName.Text) == 0)
{
this.hsPrivateWindows.Add(this.iciClient.UserName, true);
Thread th1 =
new Thread(new ThreadStart(this.OpenPrivateChatWindow));
th1.Start();
}
}
}
private void OpenPrivateChatWindow()
{
PrivateChat pc = new PrivateChat();
pc.Text = this.txtUserName.Text + " is chatting with " +
this.iciClient.UserName;
pc.CallerName = this.iciClient.UserName;
pc.MyName = this.txtUserName.Text;
pc.UserLeft += new PrivateUserLeft(this.RemoveFromPrivateList);
pc.ShowDialog();
}
private void GetMessageFromOtherClients()
{
// if (this.iciClient.ReceiverName.CompareTo
// (this.txtUserName.Text) == 0)
// {
// this.txtMessage.AppendText(Environment.NewLine);
// this.txtMessage.AppendText("Private from " +
// this.iciClient.UserName + " says: "
+ iciClient.Message);
// }
// else
if (this.iciClient.ReceiverName.CompareTo("ALL") == 0)
{
this.txtMessage.AppendText(Environment.NewLine);
this.txtMessage.AppendText(this.iciClient.UserName +
" says: " + iciClient.Message);
}
}
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
try
{
this.ReleaseHandlers();
this.im.RemoveMe(em);
}
catch (Exception ex)
{
MessageBox.Show("Server may be closed..." + ex.Message);
}
}
private void Form1_Closed(object sender, System.EventArgs e)
{
this.ReleaseHandlers();
}
public void em_UserLeftHandler(IClientImplement ici)
{
this.iciClient = ici;
Thread thLeft =
new Thread(new ThreadStart(this.UserLeftChatRoom));
thLeft.Start();
}
private void UserLeftChatRoom()
{
this.txtMessage.AppendText("\n" + this.iciClient.UserName +
" left chat at: " +
DateTime.Now.ToString());
}
private void txtSendMessage_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyValue == 13)
{
Thread th = new Thread(new ThreadStart(SendMessage));
th.Start();
}
}
private void lstUsers_DoubleClick(object sender,
System.EventArgs e)
{
bool isAdded = false;
IDictionaryEnumerator ide =
this.hsPrivateWindows.GetEnumerator();
while (ide.MoveNext())
{
if (ide.Key.ToString().CompareTo
(this.iciClient.UserName) == 0)
{
isAdded = true;
}
}
if (!isAdded)
{
Thread th = new Thread(new ThreadStart(this.BeginPrivateChat));
th.Start();
}
}
private void BeginPrivateChat()
{
this.hsPrivateWindows.Add(this.lstUsers.SelectedItem.
ToString(), true);
PrivateChat pc = new PrivateChat();
pc.Text = this.txtUserName.Text + " is chatting with " +
this.lstUsers.SelectedItem.ToString();
pc.CallerName = this.lstUsers.SelectedItem.ToString();
pc.MyName = this.txtUserName.Text;
pc.UserLeft += new PrivateUserLeft(this.RemoveFromPrivateList);
pc.ShowDialog();
}
private void Form1_Load(object sender, System.EventArgs e)
{
SplashScreen ss = new SplashScreen();
ss.Refresh();
ss.ShowDialog();
}
public void RemoveFromPrivateList(string userName)
{
Hashtable hs = new Hashtable();
IDictionaryEnumerator ide =
this.hsPrivateWindows.GetEnumerator();
while (ide.MoveNext())
{
string uName = Convert.ToString(ide.Key);
if (uName.CompareTo(userName) == 0)
{
continue;
}
else
{
hs.Add(uName, true);
}
}
this.hsPrivateWindows.Clear();
ide = hs.GetEnumerator();
while (ide.MoveNext())
{
this.hsPrivateWindows.Add(ide.Key, ide.Value);
}
}
}
/***************************************************************/
Comments
There are no comments yet. Be the first to comment!