滑动滚动显示全屏 WinForms 应用程序中的桌面 [英] Swipe scroll reveals desktop in fullscreen WinForms app

查看:26
本文介绍了滑动滚动显示全屏 WinForms 应用程序中的桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑使用在 Windows 10 上运行的 WinForms fullscreen question 中描述的方法全屏 C# WinForms 应用程序.当用户使用用于滚动的滑动"触摸手势(例如在多行 TextBox 上)并达到任一极值都有一种效果,可以在滚动方向上拉动整个窗口,从而显示桌面.这对于全屏应用程序来说是不可取的.我怎样才能摆脱这种影响?

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?

最小示例:

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);
    }
}

推荐答案

在评论中类似 answer-less 问题(归功于 defaultlocale),有提到可能的注册表配置可以防止这种行为.测试证实,虽然不是最佳选择,但它是答案.重申一下,将 HKEY_CURRENT_USER\Software\Microsoft\Wisp\Touch 键的值 Bouncing 设置为 0x0 将修复"问题.幸运的是,这是非常理想的每用户设置(不需要管理员权限/帐户).
具有固定"滚动拉动行为的修改后的最小示例:

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);
        }
    }
}

这篇关于滑动滚动显示全屏 WinForms 应用程序中的桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆