title: Vertical swipe simulated mouse events sent to wrong control in Windows Forms app on Windows 10 tablet
body: <p>I'm trying to run a Windows Forms app on a Windows 10 tablet (Dell Venue 8 Pro).  In general, Windows translates touch events into the obvious mouse event counterparts.  However, it's doing something strange with vertical swipes.</p>
  
  <p>My app has a custom control (derived directly from <code>Control</code> with a call to <code>SetStyle(ControlStyles.Selectable..., true)</code> in its constructor) that shows graphics rendered by Direct3D.  The control interprets <code>MouseDown</code> -> <code>MouseMove</code> -> <code>MouseUp</code> sequences as requests to rotate the view about the lookat position.  This works fine on the desktop, but on a tablet it breaks: vertical swipes on my custom control are somehow being caught by Windows and passed to a nearby <code>DataGridView</code>, where they are interpreted as requests to scroll through the table.  The <code>DataGridView</code> and my control are not siblings under the same container; they are at completely different levels of the control hierarchy.  Here's a screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/zLc54.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zLc54.png" alt="Screenshot of the application showing the different interpretations of vertical and horizontal swipes"></a></p>
  
  <p>I've done some debugging to prove to myself that no mouse events are making it to my control during the vertical swipe.  A few trickle in right when I lift my finger, but during the vertical swipe there's nothing.</p>
  
  <p>The trouble seems to be that my code (in the event handlers) simply isn't getting run because no input is making its way to my control.</p>
  
  <p>What is going on here, and is there any way I can tell Windows not to send vertical swipe events that happen over my control to a completely unrelated control?</p>
  
  <p><strong>Edit</strong>: I should add that I'm calling <code>Focus()</code> all over the place in my code to make sure my control is focused while the mouse is over it.  I put it in <code>OnMouseMove</code>, <code>OnMouseDown</code>, and pretty much on every other mouse event.</p>
  
  <p><strong>Edit</strong>: I have built a <a href="http://www.the-vardemans.net/andrew/stackoverflow/Windows10ScrollTest.zip" rel="nofollow noreferrer">small Visual Studio 2010 solution</a> demonstrating this problem.  It's too much code to reproduce here inline, but it's easy to grok.  Build it, install it on a Windows 10 tablet, and try swiping vertically in the rightmost control.  Note that rather than that control receiving a bunch of mouse events, the <code>DataGridView</code> fires <code>Scroll</code>.</p>
  
  <p><strong>Update</strong>: I've explicitly tested whether my control is focused when the <code>DataGridView</code> gets a <code>Scroll</code> event.  If I call <code>Focus()</code> on my control in response to <code>MouseMove</code> etc. as mentioned above, my control does get the focus and holds it during the vertical swipe while <code>DataGridView.Scroll</code> is firing.  In the <code>DataGridView.Scroll</code> event handler, I have printed out whether my control is focused, and it is.  So this is not a matter of the <code>DataGridView</code> stealing focus; it's a matter of the <code>DataGridView</code> handling a swipe intended for my control even when my control is focused.</p>
  
  <p><strong>Note</strong>: If I set <code>dataGridView.ScrollBars</code> to <code>ScrollBars.None</code>, the mouse events for the swipe do go to my control.  I've been messing with ugly hacks that hide the scrollbars every time my control gets focused and show them every time the <code>DataGridView</code> gets focused.  But they're all ugly hacks with unpleasant side effects.</p>