SayAndClear(receiverName, txtChatContent.Text, true);
txtChatContent.Focus();
}
}
/// <summary>
/// 连接聊天室
/// </summary>
private void ShowInterChatMenuItem(bool show)
{
InterChatMenuItem.Enabled = show;
OutInterChatMenuItem.Enabled = this.btnChat.Enabled = !show;
}
private void AppendText(string text)
{
txtChatDetails.Text += text;
SendMessage(txtChatDetails.Handle, WM_VSCROLL, SB_BOTTOM, new IntPtr(0));
}
/// <summary>
/// 退出应用程序时,释放使用资源
/// </summary>
private void ExitChatSession()
{
try
{
proxy.Leave();
}
catch { }
finally
{
AbortProxyAndUpdateUI();
}
}
/// <summary>
/// 释放使用资源
/// </summary>
private void AbortProxyAndUpdateUI()
{
if (proxy != null)
{
proxy.Abort();
proxy.Close();
proxy = null;
}
ShowInterChatMenuItem(true);
}
/// <summary>
/// 接收消息
/// </summary>
public void Receive(string senderName, string message)
{
AppendText(senderName + "说: " + message + Environment.NewLine);
}
/// <summary>
/// 接收私聊消息
/// </summary>
public void ReceiveWhisper(string senderName, string message)
{
AppendText(senderName + " 私下说: " + message + Environment.NewLine);
}
/// <summary>
/// 新用户登录
/// </summary>
public void UserEnter(string name)
{
AppendText("用户 " + name + " --------登录---------" + DateTime.Now.ToString() + Environment.NewLine);
lbOnlineUsers.Items.Add(name);