// ... other code ...
    private void btnAddRecord_Click(object sender, EventArgs e)
    {
        addRecord frmAddRecord = new addRecord();

        if (frmAddRecord.ShowDialog() == DialogResult.OK)
        {
            studentInfo.Add(frmAddRecord.Student);
            studentInfo.Add(frmAddRecord.Score);
            lstMarks.Items.Add(frmAddRecord.Student + " : " + frmAddRecord.Score);
        }
    }
Exemplo n.º 2
0
        //收到信息并显示
        public void add_info(string recv_str)
        {
            string[] info = recv_str.Split('.');

            if (richTextBox1.InvokeRequired)
            {
                addRecord d = new addRecord(add_info);
                this.Invoke(d, new object[] { recv_str });
            }
            else
            {
                if (info[0] == "info")
                {
                    string show_mess = info[1] + " " + info[info.Length - 1];
                    string save_mess = info[1] + "." + info[info.Length - 1];
                    richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
                    richTextBox1.AppendText(show_mess);
                    new_msg.Add(save_mess);
                }
                else if (info[0] == "file")
                {
                    string show_mess = info[1] + " " + info[info.Length - 2] + "." + info[info.Length - 1];
                    recv_filename    = recv_str.Split(' ')[recv_str.Split(' ').Length - 1];
                    recv_filename    = recv_filename.Replace("\n", "");
                    file_requestuser = user_name.IndexOf(info[1]) - 1;
                    richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
                    richTextBox1.AppendText(show_mess);
                    button_filerefuse.Show();
                    button_fileaccept.Show();
                }
                else if (info[0] == "fileaccept")
                {
                    int file_sender = user_name.IndexOf(info[1]) - 1;
                    if (!P2P_Communication.File_Send(socket_to_friend[file_sender], filepath))
                    {
                        MessageBox.Show(this, "文件发送失败", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    MessageBox.Show(this, "文件发送成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    send_state = true;
                }
                //语音聊天
                else if (info[0] == "voice")
                {
                    string show_mess = info[1] + " " + info[info.Length - 1] + "向您发起了语音通话\n";
                    richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
                    richTextBox1.AppendText(show_mess);
                    button_voicechat.Text = "接听";
                    button_voicerefuse.Show();
                }
                else if (info[0] == "voiceaccept")//接受聊天
                {
                    //voice_socket = P2P_Communication.Commun_Friend(user_name[1], socket_to_server);
                    //thread_voice_chat = new Thread(() => start_voice_chat(voice_socket));
                    //voice_socket = P2P_Communication.Commun_Friend(user_name[1], socket_to_server);
                    thread_voice_chat = new Thread(() => start_voice_chat(socket_to_friend[0]));
                    thread_voice_chat.SetApartmentState(System.Threading.ApartmentState.STA);//单线程监听控制
                    thread_voice_chat.IsBackground = true;
                    thread_voice_chat.Start();
                    button_voicechat.Text = "接听";
                    button_voicerefuse.Show();
                    button_voicerefuse.Text = "挂断";
                    label5.Show();
                }
                else if (info[0] == "voiceend")
                {
                    //end_voice_chat(socket_to_friend[0]);
                    voice_state = false;
                    thread_voice_chat.Abort();

                    string show_mess = info[1] + " " + info[info.Length - 1] + "通话结束";
                    richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
                    richTextBox1.AppendText(show_mess);
                    button_voicerefuse.Text = "拒绝";
                    button_voicechat.Text   = "音频";
                    button_voicerefuse.Hide();
                    label5.Hide();
                }
            }
        }