private void SendMsg(string Msg) { try { if (Client == null) { Client = ChatClient.Connect(ChatSetting.IP); Client.newListener(MsgComeIn); Client.CloseException(ExceptionServerExit); richTextBoxBoard.SelectionColor = Color.Blue; Client.Send($"歡迎 {FireBase.GetData(clientData)} 加入。"); } if (textBoxMsg.Text.Length > 0) { Client.Send(FireBase.GetData(clientData) + ":" + Msg); textBoxMsg.Text = ""; } } catch (Exception) { MessageBox.Show("無法連接伺服器端"); return; } }
public void ExitChatRoom() { if (Client != null) { if (Client.socket.Connected) { Client.Send(FireBase.GetData(clientData) + " 已離開"); } Client.Dispose(); Client.listenThread.Abort(); } }
//登入視窗關閉判斷 private void FormChatClient_Load(object sender, EventArgs e) { //登入視窗先顯示 FormLogin f = new FormLogin(); f.ShowDialog(); if (f.DialogResult == DialogResult.OK) { clientData = FormLogin.clientData; labelUserName.Text = FireBase.GetData(clientData); } }