问题
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