Beispiel #1
0
 //去除快捷键产生的多余的回车
 private void Input_text_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyData == (Keys.Control | Keys.Enter))
     {
         Btn_Send.PerformClick();
         Input_text.Clear();
         Input_text.Focus();
     }
 }
Beispiel #2
0
        //发送文件
        private void Btn_SendFile_Click(object sender, EventArgs e)
        {
            if (flag_FG)
            {
                string account = Current_friend.ID;

                string r = search_friend_state(account);
                if (r == "ooo" || r == "hhh" || r == "n")
                {
                    MessageBox.Show("连接不到对方");
                }
                else
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Filter = "所有文件(*.*)|*.*";
                    ofd.ShowDialog();
                    string path = ofd.FileName;
                    if (path == "")
                    {
                        return;
                    }

                    string[] temp = path.Split('\\');
                    string   name = temp[temp.Length - 1];

                    FileStream file = new FileStream(path, FileMode.Open);

                    Sender s = new Sender(r, Account_data.MyAccount);
                    if (s.SendFriendFile(name, file))
                    {
                        string str = "<Me>: " + DateTime.Now.ToString() + "\n"
                                     + name + "\n";

                        richTextBox1.AppendText(str);
                        richTextBox1.ScrollToCaret();
                        Input_text.Focus();

                        string Path = Application.StartupPath + "\\" + username + "\\" + "Contacts" + "\\";
                        if (!File.Exists(Path + Current_friend.ID + "_LTJL" + ".txt"))
                        {
                            File.Create(Path + Current_friend.ID + "_LTJL" + ".txt");
                        }
                        StreamWriter sw = new StreamWriter(Path + Current_friend.ID + "_LTJL" + ".txt", true);
                        sw.Write(str);
                        //清空缓冲区
                        sw.Flush();
                        //关闭流
                        sw.Close();
                    }
                }
            }
            else
            {
                string account = Current_group.ID;

                foreach (Friend f in Current_group.group_member)
                {
                    if (f.ID == username)//这个地方一定要改啊!!!!
                    {
                        continue;
                    }

                    string r = search_friend_state(f.ID);
                    if (r == "ooo" || r == "hhh" || r == "n")
                    {
                        //MessageBox.Show("连接不到对方");
                    }
                    else
                    {
                        OpenFileDialog ofd = new OpenFileDialog();
                        ofd.Filter = "所有文件(*.*)|*.*";
                        ofd.ShowDialog();
                        string path = ofd.FileName;
                        if (path == "")
                        {
                            return;
                        }

                        string[] temp = path.Split('\\');
                        string   name = temp[temp.Length - 1];

                        FileStream file = new FileStream(path, FileMode.Open);

                        Sender s = new Sender(r, Account_data.MyAccount);
                        if (s.SendGroupFile(Current_group.ID, name, file))
                        {
                            string str = "<Me>: " + DateTime.Now.ToString() + "\n"
                                         + name + "\n";

                            richTextBox1.AppendText(str);
                            richTextBox1.ScrollToCaret();
                            Input_text.Focus();

                            string Path = Application.StartupPath + "\\" + username + "\\" + "Contacts" + "\\";
                            if (!File.Exists(Path + account + "_LTJL" + ".txt"))
                            {
                                File.Create(Path + account + "_LTJL" + ".txt");
                            }
                            StreamWriter sw = new StreamWriter(Path + account + "_LTJL" + ".txt", true);
                            sw.Write(str);
                            //清空缓冲区
                            sw.Flush();
                            //关闭流
                            sw.Close();
                        }
                    }
                }
            }
        }
Beispiel #3
0
        //发送消息
        private void Btn_Send_Click(object sender, EventArgs e)
        {
            if (Input_text.Text == "")
            {
                Input_text.Focus();
                //SystemSounds.Beep.Play();
                return;
            }
            byte[] smsg = System.Text.Encoding.Default.GetBytes(Input_text.Text);
            if (smsg.Length > 1024)
            {
                MessageBox.Show("不要这么长好吗");
                return;
            }
            if (flag_FG)//给好友发
            {
                string account = Current_friend.ID;

                string r = search_friend_state(account);
                if (r == "ooo" || r == "hhh" || r == "n")
                {
                    MessageBox.Show("连接不到对方");
                }
                else
                {
                    Sender s = new Sender(r, Account_data.MyAccount);
                    if (s.SendFriendMessage(Input_text.Text))
                    {
                        string str = "<Me>: " + DateTime.Now.ToString() + Environment.NewLine + Input_text.Text + Environment.NewLine;
                        richTextBox1.AppendText(str);
                        //richTextBox1.AppendText(str);
                        richTextBox1.ScrollToCaret();
                        Input_text.Clear();
                        Input_text.Focus();
                        //加入聊天记录
                        string Path = Application.StartupPath + "\\" + username + "\\" + "Contacts" + "\\";
                        if (!File.Exists(Path + Current_friend.ID + "_LTJL" + ".txt"))
                        {
                            File.Create(Path + Current_friend.ID + "LTJU" + ".txt").Close();
                        }
                        StreamWriter sw = new StreamWriter(Path + Current_friend.ID + "_LTJL" + ".txt", true);
                        sw.Write(str);
                        //清空缓冲区
                        sw.Flush();
                        //关闭流
                        sw.Close();
                    }
                }
            }
            else//给群组发
            {
                string id = Current_group.ID;

                foreach (Friend f in Current_group.group_member)
                {
                    if (f.ID == username)//这个地方一定要改啊!!!!
                    {
                        continue;
                    }

                    string r = search_friend_state(f.ID);
                    if (r == "ooo" || r == "hhh" || r == "n")
                    {
                    }
                    else
                    {
                        Sender s = new Sender(r, Account_data.MyAccount);
                        if (s.SendGroupMessage(id, Input_text.Text))
                        {
                            string str = "<Me>: " + DateTime.Now.ToString() + Environment.NewLine + Input_text.Text + Environment.NewLine;
                            richTextBox1.AppendText(str);
                            richTextBox1.ScrollToCaret();
                            Input_text.Clear();
                            Input_text.Focus();
                            //加入聊天记录
                            string Path = Application.StartupPath + "\\" + username + "\\" + "Contacts" + "\\";
                            if (!File.Exists(Path + id + "_LTJL" + ".txt"))
                            {
                                File.Create(Path + id + "LTJU" + ".txt").Close();
                            }
                            StreamWriter sw = new StreamWriter(Path + id + "_LTJL" + ".txt", true);
                            sw.Write(str);
                            //清空缓冲区
                            sw.Flush();
                            //关闭流
                            sw.Close();
                        }
                    }
                }
            }
        }