Exemplo n.º 1
0
 //关闭窗口时删除mainwin的chatWinList中的这个窗口
 private void Chatwinclosing(object sender, FormClosingEventArgs e)
 {
     for (int i = 0; i < parentwin.chatWinList.Count; i++)
     {
         if ((parentwin.chatWinList[i] as ChatWin).friendID == friendID)
         {
             parentwin.chatWinList.RemoveAt(i);
             parentwin.Show();
         }
     }
 }
Exemplo n.º 2
0
 //窗口关闭时删除mainwin的filesendinglist中的这个窗口
 private void FileSendingWinClosing(object sender, FormClosingEventArgs e)
 {
     if (sending)
     {
         MessageBox.Show("文件正在发送,请勿关闭窗口");
         e.Cancel = true;
         return;
     }
     for (int i = 0; i < parentwin.fileSendingList.Count; i++)
     {
         if ((parentwin.fileSendingList[i] as FileSendingWin).friendID == friendID)
         {
             parentwin.fileSendingList.RemoveAt(i);
             parentwin.Show();
         }
     }
     sendfilethread.Abort();
 }
Exemplo n.º 3
0
        /****************登录****************/
        private void loginButton_Click(object sender, EventArgs e)
        {
            toServer = new TcpClient();
            userID   = userIDbox.Text;

            try
            {
                toServer.Connect("166.111.140.52", 8000);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            toServerStream = toServer.GetStream();

            //向服务器发送学号和密码
            string sendMsg = userIDbox.Text + "_" + passwordBox.Text;

            byte[] sendByt = Encoding.ASCII.GetBytes(sendMsg);
            toServerStream.Write(sendByt, 0, sendByt.Length);
            byte[] rcvByt    = new byte[1024];
            int    rcvLength = toServerStream.Read(rcvByt, 0, rcvByt.Length);
            string rcvMsg    = Encoding.ASCII.GetString(rcvByt, 0, rcvLength);

            //stream.Close();
            //是否成功登录
            if (rcvMsg == "lol")
            {
                try
                {
                    MainWin mainForm = new MainWin(userID, toServer);
                    this.Hide();
                    mainForm.parentform = this;
                    mainForm.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Application.Exit();
                }
            }
        }