滑动滚动显示全屏 WinForms 应用程序中的桌面

编程入门 行业动态 更新时间:2024-10-28 20:30:55
本文介绍了滑动滚动显示全屏 WinForms 应用程序中的桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

考虑使用在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 02:17:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1388528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全屏   应用程序   桌面   WinForms

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!