Swipe scroll reveals desktop in fullscreen WinForms app

夙愿已清 提交于 2019-12-11 06:58:12

问题


Consider fullscreen C# WinForms app using the approach as described in the WinForms fullscreen question running on Windows 10. When user uses the "swipe" touch gesture for scrolling (e.g. on multiline TextBox) and reaches either of the extrema there is an effect that pulls entire window in scroll direction revealing desktop. This is not desirable for fullscreen app. How can I get rid of the effect?


Minimal example:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        FormBorderStyle = FormBorderStyle.None;
        WindowState = FormWindowState.Maximized;
        var tb = new TextBox() { Multiline = true, 
                                 ScrollBars = ScrollBars.Vertical, 
                                 Dock = DockStyle.Fill, 
                                 Text = string.Concat(Enumerable.Repeat("foo! ", 10000)) };
        Controls.Add(tb);
    }
}

回答1:


In comments similar answer-less question (credit goes to defaultlocale), there was a mention of possible registry configuration that would prevent such behavior. Testing confirmed it would, though not optimal, be the answer. To reiterate, setting the HKEY_CURRENT_USER\Software\Microsoft\Wisp\Touch key's value Bouncing to 0x0 will "fix" the problem. Luckily this is per-user setting which very desirable (no need for admin rights/account).
The modified minimal example with "fixed" scroll pulling behavior:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        FormBorderStyle = FormBorderStyle.None;
        WindowState = FormWindowState.Maximized;
        var tb = new TextBox() { Multiline = true, ScrollBars = ScrollBars.Vertical, Dock = DockStyle.Fill, Text = string.Concat(Enumerable.Repeat("foo! ", 10000)) };
        Controls.Add(tb);
        DisableBouncing();
        FormClosed += (s, e) => RestoreBouncing();//for brevity just on Close
    }

    int? defaultSetting = null;
    private void DisableBouncing()
    {
        using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Wisp\Touch", true))
        {
            defaultSetting = key.GetValue(@"Bouncing", null) as int?;
            key.SetValue(@"Bouncing", 0x00000000, RegistryValueKind.DWord);
        }
    }

    private void RestoreBouncing()
    {
        using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Wisp\Touch", true))
        {
            key.SetValue(@"Bouncing", defaultSetting ?? 0, RegistryValueKind.DWord);
        }
    }
}


来源:https://stackoverflow.com/questions/50365810/swipe-scroll-reveals-desktop-in-fullscreen-winforms-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!