Exemple #1
0
        void ToolStripItem_Click(object sender, EventArgs e)
        {
            if (sender == null || !(sender is ToolStripItem))
            {
                return;
            }
            ToolStripItem item = sender as ToolStripItem;

            if (item == null)
            {
                return;
            }
            if (item.Tag == null || !(item.Tag is TextMessageData))
            {
                if (item.OwnerItem != null && item.OwnerItem is ToolStripMenuItem)
                {
                    ToolStripMenuItem owner = item.OwnerItem as ToolStripMenuItem;
                    owner.DropDownItems.Remove(item);
                    if (owner.DropDownItems.Count == 0)
                    {
                        if (owner.Owner != null)
                        {
                            ToolStrip toolStrip = owner.Owner;
                            toolStrip.Items.Remove(owner);
                        }
                    }
                }
                return;
            }

            TextMessageData textMessageData = item.Tag as TextMessageData;

            if (textMessageData == null)
            {
                return;
            }
            UserInfo userInfo = SocketCommService.GetUserInfo(textMessageData.IPAddress);

            if (userInfo == null)
            {
                return;
            }
            //MessageBox.Show(textMessageData.Text, string.Format("Received From {0} at {1}", userInfo.UserName, textMessageData.ReceiptTime));
            ReceivedMessageForm receivedMEssageForm = new ReceivedMessageForm(textMessageData, userInfo);

            receivedMEssageForm.Show();
            if (item.OwnerItem != null && item.OwnerItem is ToolStripMenuItem)
            {
                ToolStripMenuItem owner = item.OwnerItem as ToolStripMenuItem;
                owner.DropDownItems.Remove(item);
                if (owner.DropDownItems.Count == 0)
                {
                    if (owner.Owner != null)
                    {
                        ToolStrip toolStrip = owner.Owner;
                        toolStrip.Items.Remove(owner);
                    }
                }
            }
        }
Exemple #2
0
        private void ProcessTextMessage(TextMessageData textMessageData)
        {
            if (textMessageData == null)
            {
                return;
            }
            UserInfo userInfo = SocketCommService.GetUserInfo(textMessageData.IPAddress);

            if (userInfo == null)
            {
                return;
            }
            ContextMenuStrip contextMenuStrip = IPMessengerNotifyIcon.ContextMenuStrip;

            if (contextMenuStrip == null)
            {
                //MessageBox.Show(textMessageData.Text, string.Format("Received From {0} at {1}", userInfo.UserName, textMessageData.ReceiptTime));
                ReceivedMessageForm receivedMEssageForm = new ReceivedMessageForm(textMessageData, userInfo);
                receivedMEssageForm.Show();
                return;
            }
            ToolStripMenuItem receivedMessagesToolStripMenuItem;

            if (contextMenuStrip.Items.ContainsKey("Received Messages") == false)
            {
                receivedMessagesToolStripMenuItem      = new ToolStripMenuItem("Received Messages");
                receivedMessagesToolStripMenuItem.Name = "Received Messages";
                int exitIndex = contextMenuStrip.Items.IndexOfKey("Exit");
                contextMenuStrip.Items.Insert(exitIndex, receivedMessagesToolStripMenuItem);
            }
            else
            {
                receivedMessagesToolStripMenuItem = contextMenuStrip.Items["Received Messages"] as ToolStripMenuItem;
            }
            string        key           = string.Format("{0} at {1}", userInfo.UserName, textMessageData.ReceiptTime);
            ToolStripItem toolStripItem = receivedMessagesToolStripMenuItem.DropDownItems.Add(key);

            toolStripItem.Name   = key;
            toolStripItem.Tag    = textMessageData;
            toolStripItem.Click += new EventHandler(ToolStripItem_Click);

            IPMessengerNotifyIcon.Tag = textMessageData;
            string balloonToolTipText = string.Format("Received message from {0}", userInfo.UserName);

            IPMessengerNotifyIcon.ShowBalloonTip(1000, "Received Message", balloonToolTipText, ToolTipIcon.Info);
        }
Exemple #3
0
        void IPMessengerNotifyIcon_BalloonTipClicked(object sender, EventArgs e)
        {
            if (IPMessengerNotifyIcon.Tag == null || (IPMessengerNotifyIcon.Tag is TextMessageData) == false)
            {
                return;
            }
            TextMessageData textMessageData = IPMessengerNotifyIcon.Tag as TextMessageData;

            if (textMessageData == null)
            {
                return;
            }
            UserInfo userInfo = SocketCommService.GetUserInfo(textMessageData.IPAddress);

            if (userInfo == null)
            {
                return;
            }
            ContextMenuStrip contextMenuStrip = IPMessengerNotifyIcon.ContextMenuStrip;

            if (contextMenuStrip != null && contextMenuStrip.Items.ContainsKey("Received Messages"))
            {
                ToolStripMenuItem receivedMessagesToolStripMenuItem = contextMenuStrip.Items["Received Messages"] as ToolStripMenuItem;
                if (receivedMessagesToolStripMenuItem != null)
                {
                    string key   = string.Format("{0} at {1}", userInfo.UserName, textMessageData.ReceiptTime);
                    int    index = receivedMessagesToolStripMenuItem.DropDownItems.IndexOfKey(key);
                    if (index >= 0)
                    {
                        receivedMessagesToolStripMenuItem.DropDownItems.RemoveAt(index);
                        if (receivedMessagesToolStripMenuItem.DropDownItems.Count == 0)
                        {
                            contextMenuStrip.Items.Remove(receivedMessagesToolStripMenuItem);
                        }
                    }
                }
            }
            //MessageBox.Show(textMessageData.Text, string.Format("Received From {0} at {1}", userInfo.UserName, textMessageData.ReceiptTime));
            ReceivedMessageForm receivedMEssageForm = new ReceivedMessageForm(textMessageData, userInfo);

            receivedMEssageForm.Show();
        }