Home > Back-end >  WinForms Window size change (shrink) after calling Keyboard.GetKeyStates
WinForms Window size change (shrink) after calling Keyboard.GetKeyStates

Time:11-28

using .NET Framework 4.7.1

the frame or form Window size shrink after calling Keyboard.GetKeyStates Is there any reason for that ? or its a bug ? I am checking if ctrl is down or toggle on other window .

 if (((int)Keyboard.GetKeyStates(Key.LeftCtrl) == 1 || (int)Keyboard.GetKeyStates(Key.LeftCtrl) == 3))
    {
        Console.WriteLine("pressed");
    }

As can be seen in the pictures:

large image

after calling GetKeyStates

CodePudding user response:

as TnTinMn comment its Dpi aware problem ,I have found the solution here also tried to change the dpi option from app manifest ,did not work .

      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());
            }
    
    
    }
  • Related