Switch context menu location as it is done by Windows Explorer

This commit is contained in:
Peter Kirmeier 2023-09-11 18:04:48 +02:00
parent 4f1ee5385c
commit bfd50ae141
2 changed files with 1 additions and 17 deletions

View file

@ -281,17 +281,10 @@ namespace SystemTrayMenu.DataClasses
{
if (Owner != null)
{
#if CONTEXT_MENU_EXPLORER_BEHAVIOR
// Snap context menu left aligned to the ListViewItem with a small padding, but keep it vertically centered
Rect rectChild = Owner.GetDataGridViewChildRect(this);
position = Owner.GetRelativeChildPositionTo(Owner.GetDataGridView());
position.Offset(Owner.Left + rectChild.Left + 10D, Owner.Top + rectChild.Top + (rectChild.Height / 2D));
#else
// Snap context menu left and top aligned to the ListViewItem
Rect rectChild = Owner.GetDataGridViewChildRect(this);
position = Owner.GetRelativeChildPositionTo(Owner.GetDataGridView());
position.Offset(Owner.Left + rectChild.Left, Owner.Top + rectChild.Top);
#endif
}
}

View file

@ -1174,21 +1174,12 @@ namespace SystemTrayMenu.UserInterface
private void ListViewItem_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
ListViewItem lvi = (ListViewItem)sender;
RowData itemData = (RowData)lvi.Content;
#if CONTEXT_MENU_EXPLORER_BEHAVIOR
// At mouse location
Point position = Mouse.GetPosition(this);
position.Offset(Left, Top);
#else
// Snap context menu above the ListViewItem, but horizontally follow the mouse
Point position = this.GetRelativeChildPositionTo(lvi);
position.Offset(Left + Mouse.GetPosition(lvi).X, Top);
#endif
isShellContextMenuOpen = true;
itemData.OpenShellContextMenu(position);
((RowData)((ListViewItem)sender).Content).OpenShellContextMenu(position);
isShellContextMenuOpen = false;
}
}