Beispiel #1
0
 private void buttonLogin_Click(object sender, EventArgs e)
 {
     //参数判断
     if (TextBoxAdr.Text == "" || TextBoxName.Text == "" || textBoxCom.Text == "")
     {
         MessageBox.Show("请输入正确参数", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
     }
     else
     {
         try
         {
             LabLogin.Text = "正在连接到服务器……";
             //切换窗口
             ListFrom listFrom = new ListFrom();
             client          = new SocketTcp(TextBoxName.Text, TextBoxAdr.Text, int.Parse(textBoxCom.Text));
             listFrom.client = client;
             this.Hide();
             listFrom.ShowDialog();
             this.Close();
         }
         catch (SocketException)
         {
             LabLogin.Text = "请登录";
             MessageBox.Show("无法连接到服务器……", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
         }
     }
 }
Beispiel #2
0
        public void ReceiveChatMsg(string str)
        {
            string aim;

            string [] strArray;
            string    rec;

            str      = str.Substring(3, str.Length - 3);
            strArray = str.Split('/');
            aim      = strArray[0];
            rec      = strArray[1];

            ChatForm aimForm = null;

            foreach (var temp in listFrom.chatList)
            {
                if (temp.chat.aim == aim)
                {
                    aimForm = temp;
                }
            }
            if (aimForm == null)
            {
                int n   = 0;
                int ans = -1;
                foreach (var temp in listFrom.listOnl.Items)
                {
                    if (temp.ToString() == aim || temp.ToString() == aim + "*")
                    {
                        ans = n;
                    }
                    n++;
                }

                if (ans == -1)
                {
                    listFrom.richlist.Text += rec + "\n";
                }
                else
                {
                    listFrom.listOnl.Items[ans] = aim + "*";
                    listFrom.Addbuff           += rec + "\n";
                }
            }
            else
            {
                aimForm.ricTexReceive.Text += rec + "\n";
                SocketTcp.SaveLog(name, aimForm.chat.aim, rec);
                //让文本框获取焦点
                aimForm.ricTexReceive.Focus();
                //设置光标的位置到文本尾
                aimForm.ricTexReceive.Select(aimForm.ricTexReceive.TextLength, 0);
                //滚动到控件光标处
                aimForm.ricTexReceive.ScrollToCaret();
                aimForm.ricTexSend.Focus();
            }
        }
Beispiel #3
0
        public void buttonChat_Click(object sender, EventArgs e)
        {
            try
            {
                bool     flag     = false;
                bool     exsit    = false;
                string   aim      = listOnl.SelectedItem.ToString();
                ChatForm chatForm = null;

                if (aim.EndsWith("*"))
                {
                    flag = true;
                    //chatForm.ricTexReceive.Text += Addbuff + "\n";
                    aim = aim.Substring(0, aim.Length - 1);
                    listOnl.Items[listOnl.Items.IndexOf(listOnl.SelectedItem)] = aim;
                }
                foreach (var temp in chatList)
                {
                    if (temp.chat.aim == aim)
                    {
                        MessageBox.Show("对话框已存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                        exsit = true;
                    }
                }
                if (exsit == false)
                {
                    chatForm            = new ChatForm();
                    chatForm.fatherWind = this;
                    chatList.Add(chatForm);
                    chatForm.chat.startIP = client;
                    chatForm.chat.aim     = aim;
                    chatForm.Show();
                }
                if (flag == true)
                {
                    /*
                     * foreach (var temp in listOnl.Items)
                     * {
                     *  if (temp.ToString() == aim)
                     *      ans = n;
                     *  n++;
                     * }
                     * listOnl.Items[ans] = aim;
                     */
                    chatForm.ricTexReceive.Text += Addbuff;
                    SocketTcp.SaveLog(client.name, aim, Addbuff);
                    Addbuff = "";
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请选择聊天对象", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
            }
        }
Beispiel #4
0
        private void buttonChatSend_Click(object sender, EventArgs e)
        {
            string front = chat.startIP.name + "\t" + DateTime.Now.ToShortTimeString() + "\n";

            SendBuff = ricTexSend.Text.TrimEnd();
            SendBuff = front + SendBuff + "\n";
            ricTexSend.Clear();
            ricTexReceive.Text += SendBuff;
            SocketTcp.SaveLog(chat.startIP.name, chat.aim, SendBuff);
            //让文本框获取焦点
            ricTexReceive.Focus();
            //设置光标的位置到文本尾
            ricTexReceive.Select(ricTexReceive.TextLength, 0);
            //滚动到控件光标处
            ricTexReceive.ScrollToCaret();
            ricTexSend.Focus();
            chat.startIP.SendChat(SendBuff, this);
        }
Beispiel #5
0
 public void SendSerch()
 {
     SocketTcp.Send("++-", stream);
 }
Beispiel #6
0
 public void SendName()
 {
     SocketTcp.Send("+++" + name, stream);
 }
Beispiel #7
0
 public void ChatConnect(string aim)
 {
     SocketTcp.Send("+--" + aim, stream);
     //listFrom.richlist.Text += aim + "\n";
 }