Пример #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
            var location      = Cursor.Position;
            var menuRectangle = new NativeRect(location, menu.Size).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
            // TODO: Get a handle
            // User32Api.SetForegroundWindow(PluginUtils.Host.NotifyIcon.ContextMenuStrip.Handle);
            menu.Show(location);
            menu.Focus();

            // Wait for the menu to close
            while (true)
            {
                if (menu.Visible)
                {
                    Application.DoEvents();
                    Thread.Sleep(200);
                }
                else
                {
                    //menu.Dispose();
                    break;
                }
            }
        }
Пример #2
0
 /// <summary>
 ///     Default Constructor
 /// </summary>
 public Capture()
 {
     _screenBounds   = WindowCapture.GetScreenBounds();
     _captureDetails = new CaptureDetails();
 }