Пример #1
0
        private void SetForm(string body)
        {
            const string SPLITER = ",";

            string source = body;
            int    pos_1  = source.IndexOf(SPLITER);
            int    pos_2  = source.IndexOf(SPLITER, pos_1 + 1);

            // data 顺序:发送者,消息类型,消息
            string sender   = source.Substring(0, pos_1);
            string msg_type = source.Substring(pos_1 + 1, pos_2 - pos_1 - SPLITER.Length);
            string msg      = source.Substring(pos_2 + SPLITER.Length);

            ui_chat form_chat_with = null;

            foreach (Friend friend in friends_list)
            {
                if (friend.Username == sender)
                {
                    form_chat_with = ui_chat.GetInstance(friend.Username, friend.Notename);
                    form_chat_with.Show();

                    break;
                }
            }

            if (form_chat_with != null)
            {
                form_chat_with.Invoke(
                    form_chat_with.show_text,
                    new Object[] { msg, msg_type, form_chat_with.rtbx_receive_msg }
                    );
            }
            else
            {
                // 陌生人
            }
        }
Пример #2
0
        private void tmenu_item_send_msg_Click(object sender, EventArgs e)
        {
            try
            {
                string notename = lsb_friends.SelectedItem.ToString();
                foreach (Friend friend in friends_list)
                {
                    if (friend.Notename == notename)
                    {
                        ui_chat form_chat_with = ui_chat.GetInstance(friend.Username, friend.Notename);
                        form_chat_with.Show();
                        form_chat_with.Activate();

                        return;
                    }
                }

                throw new Exception("无此好友!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("未选中好友!");
            }
        }