Here's a way to make it work:
1. Do not set the Control.ContextMenu property. You must leave null or
you won't get the left mouse button down event.
2. Set a new property of your control (called mTapHoldMenu) to a new
ContextMenu.
3. In your control class add these:
protected const uint GN_CONTEXTMENU = 1000;
protected const uint SHRG_RETURNCMD = 0x00000001;
[StructLayout(LayoutKind.Sequential)]
protected class SHRGINFO {
public uint cbSize;
public IntPtr hwndClient;
public int x;
public int y;
public uint dwFlags;
}
[DllImport("coredll")]
extern static IntPtr GetCapture();
[DllImport("aygshell")]
extern static uint SHRecognizeGesture(SHRGINFO shrgInfo);
4. In the OnMouseDown() function, call this:
if (mTapHoldMenu != null) {
Capture = true;
hWnd = GetCapture();
Capture = false;
SHRGINFO shrgInfo = new SHRGINFO();
shrgInfo.cbSize = (uint) Marshal.SizeOf(shrgInfo);
shrgInfo.hwndClient = hWnd;
shrgInfo.x = e.X;
shrgInfo.y = e.Y;
shrgInfo.dwFlags = SHRG_RETURNCMD;
if (SHRecognizeGesture(shrgInfo) == GN_CONTEXTMENU)
mTapHoldMenu.Show(this, new Point(e.X, e.Y));
}