示例#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();
     }
 }
示例#2
0
 private void Tłumacz_DragDrop(object sender, DragEventArgs e)
 {
     Input_text.Clear();
     try
     {
         Array a = (Array)e.Data.GetData(DataFormats.FileDrop);
         if (a != null)
         {
             string       s             = a.GetValue(0).ToString();
             StreamReader StreamReader1 = new StreamReader(s);
             Input_text.Text = StreamReader1.ReadToEnd();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error in DragDrop function: " + ex.Message);
     }
 }
示例#3
0
 private void button1_Click(object sender, EventArgs e)
 {
     Input_text.Clear();
 }
示例#4
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();
                        }
                    }
                }
            }
        }
示例#5
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();
                        }
                    }
                }
            }
        }
示例#6
0
        //点击聊天
        private void label_MouseClick(object sender, MouseEventArgs e)
        {
            Label text = (Label)sender;

            string target_id = text.Text.ToString();

            if (flag_FG)
            {
                Current_group  = null;
                Current_friend = new Friend(target_id);
            }
            else
            {
                Current_friend = null;
                Current_group  = new Group(target_id);
            }

            if (pre_panel != null)
            {
                pre_panel.BackColor = Color.FromArgb(245, 245, 245);
            }

            text.Parent.BackColor = Color.FromArgb(220, 220, 220);

            pre_panel = (Panel)text.Parent;

            Chat_label.Text      = "聊天对象:" + target_id;
            Chat_label.Visible   = true;
            Input_text.Visible   = true;
            Btn_Send.Enabled     = true;
            Btn_emoji.Enabled    = true;
            Btn_SendFile.Enabled = true;
            richTextBox1.Visible = true;

            richTextBox1.Clear();
            Input_text.Clear();

            //读取聊天记录
            string Path = Application.StartupPath + "\\" + username + "\\" + "Contacts" + "\\";

            if (!File.Exists(Path + target_id + "_LTJL" + ".txt"))
            {
                File.Create(Path + target_id + "_LTJL" + ".txt").Close();
            }
            StreamReader file = new StreamReader(Path + target_id + "_LTJL" + ".txt");
            String       line;

            while ((line = file.ReadLine()) != null)
            {
                if (line == "sticker_1" || line == "sticker_2" || line == "sticker_3")//如果是表情
                {
                    string s = line.Substring(line.Length - 1, 1);
                    int    t = int.Parse(s);
                    //richTextBox1.ReadOnly = false;

                    //SetClipboard2(images[t - 1]);
                    Clipboard.SetImage(images[t - 1]);
                    richTextBox1.Paste();
                    richTextBox1.AppendText(Environment.NewLine);
                    richTextBox1.ScrollToCaret();
                    //richTextBox1.ReadOnly = true;
                    continue;
                }
                richTextBox1.AppendText(line);
                richTextBox1.AppendText("\r\n");
                richTextBox1.ScrollToCaret();
            }
            file.Close();
        }