Beispiel #1
0
        void ChatImage_Click(object sender, EventArgs e)
        {
            try{

            if(f!=null)
                if (!f.IsDisposed)
                    f.Dispose();

            formpresent = false;

            Control cntrl = (Control)sender;

            if (cntrl.Name.Equals("NewMessageButton"))
                chatfrom = boxname;
            else
            {
                if (f != null)
                {
                   chatfrom = f.Name;
                }
                else if (f == null)
                {
                    chatfrom = cntrl.Parent.Name;
                }

            }

            foreach (Form OpenForm in Application.OpenForms)
            {
                if (OpenForm.Name.Equals(chatfrom) &&OpenForm.GetType().Name.Equals("ChatForm"))
                {
                    if (OpenForm.Name.Equals(chatfrom))
                    {
                        formpresent = true;
                        f1 =(ChatForm) OpenForm;
                        break;
                    }
                }
            }
            if (formpresent == true)
            {
                if (f1.WindowState == FormWindowState.Minimized)
                {
                    f1.WindowState = FormWindowState.Normal;
                }
                else
                    f1.Activate();
                //f1.webBrowser1.DocumentText

            }
            else if (formpresent == false)
            {

                c = new ChatForm();
                c.Name = chatfrom;

                if (String.IsNullOrEmpty(contactsRoster[chatfrom].Name))
                {
                    c.Titlelabel.Text = contactsRoster[chatfrom].Jid.Bare;

                }
                else
                {
                    c.Titlelabel.Text = contactsRoster[chatfrom].Name;

                }

                if (VCardImage.ContainsKey(chatfrom))
                {
                    if (VCardImage[chatfrom] != null)
                    {
                        c.Contactpicture.Image = VCardImage[chatfrom];
                    }
                    else
                    {
                        c.Contactpicture.Image = Properties.Resources.Moon;
                    }
                }
                else
                {
                    c.Contactpicture.Image = Properties.Resources.Moon;
                }

                c.MyPicture.Image = mypicture;
                c.Text = c.Titlelabel.Text;
                //if (f != null)
                //    if (!f.IsDisposed)
                //        f.Dispose();
                c.Show();

            }
            }
            catch
            {
                MessageBox.Show("form1:chatimage click");
            }
        }
Beispiel #2
0
        void xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            // ignore empty messages (events)

            if (InvokeRequired)
            {
                BeginInvoke(new agsXMPP.protocol.client.MessageHandler(xmpp_OnMessage), new object[] { sender, msg });
                return;
            }
            try{
            if (msg.Body == null)
                return;

            boxname = msg.From.Bare;

            //Check if window exist,if not open new window
            EventArgs arg = new EventArgs();
            ChatImage_Click((object)NewMessageButton, arg);

            chatformpresent = false;
            foreach (Form OpenForm in Application.OpenForms)
            {
                if (OpenForm.Name.Equals(chatfrom) && OpenForm.GetType().Name.Equals("ChatForm"))
                {
                    if (OpenForm.Name.Equals(boxname))
                    {
                        chatformpresent = true;
                        f2 = (ChatForm)OpenForm;
                        break;
                    }
                }
            }

                if (chatformpresent == true)
                {
                    f2.displaymessage(boxname, msg.Body);
                }

            }
            catch
            {
                MessageBox.Show("Form1:on message");
            }
        }