/// <summary> /// Closes the context menu control shopwn earlier (if it's still visible at all). /// </summary> internal void CloseContextMenu(ICtxtMenuControl ctxtMenuCtrl) { if (ctxtForm != null && ctxtMenuCtrl == ctxtForm.CtxtMenuControl) { ctxtForm.Close(); ctxtForm = null; } }
public override void Dispose() { if (ctxtForm != null) { ctxtForm.Dispose(); ctxtForm = null; } form.Dispose(); if (canvas != null) { try { canvasMutex.WaitOne(); canvas.Dispose(); canvas = null; } finally { canvasMutex.ReleaseMutex(); } } base.Dispose(); }
/// <summary> /// Shows a context menu at the desired location, or the nearest best place. /// </summary> /// <param name="screenLoc">The desired location in screen coordinates.</param> /// <param name="ctxtMenuCtrl">The context menu UI to show.</param> internal void ShowContextMenu(Point screenLoc, ICtxtMenuControl ctxtMenuCtrl) { // If we currently have a context menu on the screen, kill it. if (ctxtForm != null) { ctxtForm.Close(); ctxtForm = null; } // Create new form var ff = new CtxtMenuForm(ctxtMenuCtrl); // Calculate optimal location. // Horizontally: centered around pointer // Vertically: prefer above, with 3px in between Screen scr = getScreenForPoint(screenLoc); int x = screenLoc.X - ff.Width / 2; if (x < scr.WorkingArea.Left) { x = scr.WorkingArea.Left; } else if (x + ff.Width > scr.WorkingArea.Right) { x = scr.WorkingArea.Right - ff.Width; } int y = screenLoc.Y - ff.Height - 3; if (y < scr.WorkingArea.Top) { y = screenLoc.Y + 3; } ff.Location = new Point(x, y); // Show context menu ff.Show(form); form.Focus(); ctxtForm = ff; }
/// <summary> /// Shows a context menu at the desired location, or the nearest best place. /// </summary> /// <param name="screenLoc">The desired location in screen coordinates.</param> /// <param name="ctxtMenuCtrl">The context menu UI to show.</param> internal void ShowContextMenu(Point screenLoc, ICtxtMenuControl ctxtMenuCtrl) { // If we currently have a context menu on the screen, kill it. if (ctxtForm != null) { ctxtForm.Close(); ctxtForm = null; } // Create new form var ff = new CtxtMenuForm(ctxtMenuCtrl); // Calculate optimal location. // Horizontally: centered around pointer // Vertically: prefer above, with 3px in between Screen scr = getScreenForPoint(screenLoc); int x = screenLoc.X - ff.Width / 2; if (x < scr.WorkingArea.Left) x = scr.WorkingArea.Left; else if (x + ff.Width > scr.WorkingArea.Right) x = scr.WorkingArea.Right - ff.Width; int y = screenLoc.Y - ff.Height - 3; if (y < scr.WorkingArea.Top) y = screenLoc.Y + 3; ff.Location = new Point(x, y); // Show context menu ff.Show(form); form.Focus(); ctxtForm = ff; }