title: How can I detect when Windows 10 enters tablet mode in a Windows Forms application?
body: <p><strong>Update</strong></p>
  
  <p>While not the most elegant solution, one method that seems to work is to watch the relevant registry value. Here's an example using WMI to do this. I'd be happy to hear from anyone if there's a better solution than this.</p>
  
  <pre><code>using System;
  using System.Management;
  using System.Security.Principal;
  using System.Windows.Forms;
  using Microsoft.Win32;
  
  public partial class MainForm : Form
  {
      public MainForm()
      {
          this.InitializeComponent();
          this.UpdateModeFromRegistry();
  
          var currentUser = WindowsIdentity.GetCurrent();
          if (currentUser != null &amp;&amp; currentUser.User != null)
          {
              var wqlEventQuery = new EventQuery(string.Format(@"SELECT * FROM RegistryValueChangeEvent WHERE Hive='HKEY_USERS' AND KeyPath='{0}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ImmersiveShell' AND ValueName='TabletMode'", currentUser.User.Value));
              var managementEventWatcher = new ManagementEventWatcher(wqlEventQuery);
              managementEventWatcher.EventArrived += this.ManagementEventWatcher_EventArrived;
              managementEventWatcher.Start();
          }
      }
  
      private void ManagementEventWatcher_EventArrived(object sender, EventArrivedEventArgs e)
      {
          this.UpdateModeFromRegistry();
      }
  
      private void UpdateModeFromRegistry()
      {
          var tabletMode = (int)Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ImmersiveShell", "TabletMode", 0);
          if (tabletMode == 1)
          {
              Console.Write(@"Tablet mode is enabled");
          }
          else
          {
              Console.Write(@"Tablet mode is disabled");
          }
      }
  }
  </code></pre>
  
  <p><strong>Original Question</strong></p>
  
  <p>I'm interested in make some optimizations in my Windows Forms application based on whether a user is in "Tablet Mode" (or not) using the new Windows 10 Continuum feature.</p>
  
  <p>There is some guidance on how to do this in a UWP project at <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/dn917883(v=vs.85).aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/windows/hardware/dn917883(v=vs.85).aspx</a> (i.e. check the current view's UserInteractionMode to see if it's UserInteractionMode.Mouse or UserInteractionMode.Touch), however I'm not sure if or how I can do the same in Windows Forms.</p>
  
  <p>Would there be any way I can call the necessary UWP APIs from my Windows Forms application, or is there some Windows Forms equivalent I can use?</p>