You could try implementing the IMessageFilter interface on your form. There are several other discussions and documentation on it. One possible solution for you might look like (create a form, place a button on it, add the necessary code from below, run it and try right clicking on the form and on the button):
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form, IMessageFilter
{
private const int WM_RBUTTONUP = 0x0205;
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetCapture();
public Form1()
{
InitializeComponent();
Application.AddMessageFilter(this);
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_RBUTTONUP)
{
System.Diagnostics.Debug.WriteLine("pre wm_rbuttonup");
// Get a handle to the control that has "captured the mouse". This works
// in my simple test. You can read the documentation and do more research
// on it if you'd like:
// http://msdn.microsoft.com/en-us/library/ms646257(v=VS.85).aspx
IntPtr ptr = GetCapture();
System.Diagnostics.Debug.WriteLine(ptr.ToString());
Control control = System.Windows.Forms.Control.FromChildHandle(ptr);
System.Diagnostics.Debug.WriteLine(control.Name);
// Return true if you want to stop the message from going any further.
//return true;
}
return false;
}
}
}