Exemple #1
0
        void SendMessage()
        {
            if (_client.socket.Connected)
            {
                rTB_content.Text = rTB_content.Text.Trim();
                if (rTB_content.Text != "\n" && rTB_content.Text != "")
                {
                    //chưa gởi hoặc đã nhận thì gởi message
                    if (_bSend && _bRecive)//chưa gởi và chưa nhận
                    {
                        string _time = DateTime.Now.ToString();
                        Button a = new Button();
                        a.Width = 490;
                        a.Text = _time;
                        a.BackColor = System.Drawing.Color.Transparent;
                        a.Dock = DockStyle.None;
                        a.FlatAppearance.BorderSize = 0;
                        a.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                        a.Enabled = false;
                        flp_messeage.Controls.Add(a);

                    }
                    if (_bSend )
                    {
                        Messeage ms = new Messeage(_client.userName, rTB_content.Text, _fontMessage);
                        ms.Anchor = AnchorStyles.Right;
                        flp_messeage.Controls.Add(ms);
                        _fontMessage = rTB_content.Font;
                        flp_messeage.ScrollControlIntoView(ms);
                        _bSend = false;//đã send và chưa nhận
                        _bRecive = true;
                        MessageText mst = new MessageText(rTB_content.Text, _fontMessage, 1);
                        listmessage.AddLast(mst);
                    }
                    else
                    {
                        Message1 ms = new Message1( rTB_content.Text, _fontMessage);
                        ms.Anchor = AnchorStyles.Right;
                        flp_messeage.Controls.Add(ms);
                        _fontMessage = rTB_content.Font;
                        flp_messeage.ScrollControlIntoView(ms);
                        //int a = flp_messeage.VerticalScroll.Value;
                        MessageText mst = new MessageText(rTB_content.Text, _fontMessage, 1);
                        listmessage.AddLast(mst);
                    }
                    if (_usernameReference == "Server")
                    {
                        Command cmd = new Command(Enum.CommandType_.Message, rTB_content.Text, _fontMessage);
                        _client.SendCommand(cmd);
                    }
                    else
                    {
                        Command cmd = new Command(Enum.CommandType_.MessageFriend, this._usernameReference, rTB_content.Text, _fontMessage);
                        _client.SendCommand(cmd);
                    }
                    rTB_content.Text = "";
                }
                else
                {
                    rTB_content.Text = "";
                }
            }
            else
            {
                MessageCustom.Show("Kết nối với client đã bị đóng!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
            }
        }
Exemple #2
0
 public void Receive(string userFriend, string content, Font _fontTemp)
 {
     if (bLoadMessage)
     {
         MessageText mst = new MessageText(content, _fontTemp, 2);
         listmessage.AddLast(mst);
         Command cmd = new Command(Enum.CommandType_.LoadMessage, userFriend, listmessage.Count);
         _client.SendCommand(cmd);
         bLoadMessage = false;
     }
     else
     {
         if (flp_messeage.InvokeRequired)
         {
             this.Invoke(new Receive_delagate(Receive), userFriend, content, _fontTemp);
         }
         else
         {
             if (_bSend && _bRecive)//chưa gởi và chưa nhận
             {
                 string _time = DateTime.Now.ToString();
                 Button a = new Button();
                 a.Width = 490;
                 a.Text = _time;
                 a.BackColor = System.Drawing.Color.Transparent;
                 a.Dock = DockStyle.None;
                 a.FlatAppearance.BorderSize = 0;
                 a.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                 a.Enabled = false;
                 flp_messeage.Controls.Add(a);
             }
             if (_bRecive)
             {
                 Messeage ms = new Messeage(userFriend, content, _fontTemp);
                 ms.Anchor = AnchorStyles.Left;
                 flp_messeage.Controls.Add(ms);
                 flp_messeage.ScrollControlIntoView(ms);
                 _bSend = true;
                 _bRecive = false;
                 MessageText mst = new MessageText(content, _fontTemp, 2);
                 listmessage.AddLast(mst);
             }
             else
             {
                 Message1 ms = new Message1(content, _fontTemp);
                 ms.Anchor = AnchorStyles.Left;
                 flp_messeage.Controls.Add(ms);
                 flp_messeage.ScrollControlIntoView(ms);
                 MessageText mst = new MessageText(content, _fontTemp, 2);
                 listmessage.AddLast(mst);
             }
         }
     }
 }
Exemple #3
0
        public void update_message(bool kt)
        {
            if (flp_messeage.InvokeRequired)
            {
                this.flp_messeage.Invoke(new UpDate_message_delegate(update_message), new object[] { kt });
            }
            else
            {
                if (kt)
                {
                    List<Control> listControls = flp_messeage.Controls.Cast<Control>().ToList();
                    foreach (Control control in listControls)
                    {
                        flp_messeage.Controls.Remove(control);
                        control.Dispose();
                    }
                }
                _bSend = true;
                _bRecive = true;
                LinkedListNode<MessageText> msTemp = listmessage.First;
                while (msTemp != null)
                {
                    if (_bSend && _bRecive)//chưa gởi và chưa nhận
                    {
                        string _time = DateTime.Now.ToString();
                        Button a = new Button();
                        a.Width = 490;
                        a.Text = _time;
                        a.BackColor = System.Drawing.Color.Transparent;
                        a.Dock = DockStyle.None;
                        a.FlatAppearance.BorderSize = 0;
                        a.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                        a.Enabled = false;
                        flp_messeage.Controls.Add(a);
                    }
                    if (msTemp.Value.type==2)
                    {
                        if (_bRecive)
                        {
                            Messeage ms = new Messeage(this.Text, msTemp.Value.content, msTemp.Value.font);
                            ms.Anchor = AnchorStyles.Left;
                            flp_messeage.Controls.Add(ms);

                            if (msTemp.Next == null)
                            {
                                if (load == 1)
                                {
                                    flp_messeage.ScrollControlIntoView(ms);

                                    load++;
                                }
                            }
                            _bSend = true;
                            _bRecive = false;

                        }
                        else
                        {
                            Message1 ms = new Message1(msTemp.Value.content, msTemp.Value.font);
                            ms.Anchor = AnchorStyles.Left;
                            flp_messeage.Controls.Add(ms);
                            if (msTemp.Next == null)
                            {
                                if (load == 1)
                                {
                                    flp_messeage.ScrollControlIntoView(ms);

                                    load++;
                                }
                            }
                        }
                    }
                    if (msTemp.Value.type == 1)
                    {
                        if (_bSend)
                        {
                            Messeage ms = new Messeage(_client.userName,msTemp.Value.content, msTemp.Value.font);
                            ms.Anchor = AnchorStyles.Right;
                            flp_messeage.Controls.Add(ms);
                            _fontMessage = rTB_content.Font;
                            if (msTemp.Next == null)
                            {
                                if (load == 1)
                                {
                                    flp_messeage.ScrollControlIntoView(ms);

                                    load++;
                                }
                            }
                            _bSend = false;//đã send và chưa nhận
                            _bRecive = true;

                        }
                        else
                        {
                            Message1 ms = new Message1(msTemp.Value.content, msTemp.Value.font);
                            ms.Anchor = AnchorStyles.Right;
                            flp_messeage.Controls.Add(ms);
                            _fontMessage = rTB_content.Font;

                            if (msTemp.Next == null)
                            {
                                if (load == 1)
                                {
                                    flp_messeage.ScrollControlIntoView(ms);

                                    load++;
                                }
                            }
                            //int a = flp_messeage.VerticalScroll.Value;

                        }
                    }
                    msTemp = msTemp.Next;
                }
                //flp_messeage.VerticalScroll.Value = 200;
            }
            bLoad = true;
        }