调用 Keyboard.GetKeyStates 后 WinForms Window 大小更改(缩小)
WinForms Window size change (shrink) after calling Keyboard.GetKeyStates
使用 .NET Framework 4.7.1
框架或表格 Window 调用后尺寸缩小 Keyboard.GetKeyStates
有什么理由吗?或者它是一个错误?
我正在检查 ctrl 是否关闭或切换到其他 window .
if (((int)Keyboard.GetKeyStates(Key.LeftCtrl) == 1 || (int)Keyboard.GetKeyStates(Key.LeftCtrl) == 3))
{
Console.WriteLine("pressed");
}
如图所示:
large image
after calling GetKeyStates
as TnTinMn 评论它的 Dpi 感知问题,我找到了解决方案
here
还尝试从应用程序清单更改 dpi 选项,但没有用。
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
//add this line
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
static void Main()
{
//add this line
if (Environment.OSVersion.Version.Major >= 6)
SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
使用 .NET Framework 4.7.1
框架或表格 Window 调用后尺寸缩小 Keyboard.GetKeyStates 有什么理由吗?或者它是一个错误? 我正在检查 ctrl 是否关闭或切换到其他 window .
if (((int)Keyboard.GetKeyStates(Key.LeftCtrl) == 1 || (int)Keyboard.GetKeyStates(Key.LeftCtrl) == 3)) { Console.WriteLine("pressed"); }
如图所示:
large image
after calling GetKeyStates
as TnTinMn 评论它的 Dpi 感知问题,我找到了解决方案 here 还尝试从应用程序清单更改 dpi 选项,但没有用。
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
//add this line
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
static void Main()
{
//add this line
if (Environment.OSVersion.Version.Major >= 6)
SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}