Ejemplo n.º 1
0
        /// <summary>
        /// This method will show the supplied context menu at the mouse cursor, also makes sure it has focus and it's not visible in the taskbar.
        /// </summary>
        /// <param name="menu"></param>
        private static void ShowMenuAtCursor(ContextMenuStrip menu)
        {
            // find a suitable location
            Point     location      = Cursor.Position;
            Rectangle menuRectangle = new Rectangle(location, menu.Size);

            menuRectangle.Intersect(WindowCapture.GetScreenBounds());
            if (menuRectangle.Height < menu.Height)
            {
                location.Offset(-40, -(menuRectangle.Height - menu.Height));
            }
            else
            {
                location.Offset(-40, -10);
            }
            // This prevents the problem that the context menu shows in the task-bar
            User32.SetForegroundWindow(PluginUtils.Host.NotifyIcon.ContextMenuStrip.Handle);
            menu.Show(location);
            menu.Focus();

            // Wait for the menu to close, so we can dispose it.
            while (true)
            {
                if (menu.Visible)
                {
                    Application.DoEvents();
                    Thread.Sleep(100);
                }
                else
                {
                    menu.Dispose();
                    break;
                }
            }
        }
 /// <summary>
 /// Default Constructor
 /// </summary>
 public Capture()
 {
     _screenBounds   = WindowCapture.GetScreenBounds();
     _captureDetails = new CaptureDetails();
 }