Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public ReceivedMessageForm(TextMessageData textMessageData)
        {
            if (textMessageData == null)
            {
                throw new ArgumentNullException("textMessageData", "Something is wrong. TextMessageData should not be null.");
            }
            ReceivedTextMessageData = textMessageData;

            ReceivedUserInfo = SocketCommService.GetUserInfo(textMessageData.IPAddress);
            if (ReceivedUserInfo == null)
            {
                throw new Exception("Text message received from unknown user");
            }

            InitializeComponent();

            StringBuilder stringBuilder = new StringBuilder("Received message from ");

            stringBuilder.Append(ReceivedUserInfo.UserName);
            if (ReceivedUserInfo.LogOnName != ReceivedUserInfo.UserName)
            {
                stringBuilder.AppendFormat(" [{0}]", ReceivedUserInfo.LogOnName);
            }
            stringBuilder.AppendFormat(" ({0})", ReceivedUserInfo.MachineName);
            stringBuilder.AppendFormat("{0}at {1}", Environment.NewLine, ReceivedTextMessageData.ReceiptTime);

            MessegeInfoLabel.Text = stringBuilder.ToString();
            MessegeTextBox.Text   = ReceivedTextMessageData.Text;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
        }