Пример #1
0
        private void OnToolStripDropDownClosing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            ToolStripDropDown tToolStripDropDown = sender as ToolStripDropDown;
            //use pointer location to see if the user is inside the menu item
            Point p = tToolStripDropDown.PointToClient(MousePosition);

            if (tToolStripDropDown.DisplayRectangle.Contains(p))
            {
                e.Cancel = true;  // stop the auto closing on click
            }
        }
Пример #2
0
        public static void DropdownClosed(object sender, EventArgs e)
        {
            ToolStripDropDownItem ddItem = (ToolStripDropDownItem)sender;
            ToolStripDropDown     parent = ddItem.GetCurrentParent() as ToolStripDropDown;

            if (parent != null)
            {
                Point pos = parent.PointToClient(Cursor.Position);
                if (pos.X < 0 || pos.Y < 0 || pos.X > parent.Width || pos.Y > parent.Height)
                {
                    //When closing a dropdown, if the mouse isn't inside its parent, close all the parent, too.
                    parent.Close();
                }
            }

            _openedDropdowns.Remove(ddItem.DropDown);
        }
Пример #3
0
 public bool PreFilterMessage(ref Message msg)
 {
     if (ToolStripDropDown.Visible)
     {
         switch (msg.Msg)
         {
         case WinApi.WM_LBUTTONDOWN:
         case WinApi.WM_RBUTTONDOWN:
         case WinApi.WM_MBUTTONDOWN:
         case WinApi.WM_NCLBUTTONDOWN:
         case WinApi.WM_NCRBUTTONDOWN:
         case WinApi.WM_NCMBUTTONDOWN:
         {
             int   i  = unchecked ((int)(long)msg.LParam);
             short x  = (short)(i & 0xFFFF);
             short y  = (short)((i >> 16) & 0xFFFF);
             Point pt = new Point(x, y);
             WinApi.MapWindowPoints(msg.HWnd, ToolStripDropDown.Handle, ref pt, 1);
             if (!ToolStripDropDown.ClientRectangle.Contains(pt))
             {
                 if (!ToolStripDropDown.ClientRectangle.Contains(ToolStripDropDown.PointToClient(new Point(x, y))))
                 {
                     pt = new Point(x, y);
                     WinApi.MapWindowPoints(msg.HWnd, Handle, ref pt, 1);
                     if (!ClientRectangle.Contains(pt))
                     {
                         HideToolStrip();
                     }
                 }
             }
             break;
         }
         }
     }
     return(false);
 }