GetSystemMetrics() returns different results for .NET 4.5 & .NET 4.0

后端 未结 2 506
有刺的猬
有刺的猬 2020-12-02 00:20

During a .NET 4.0 -> .NET 4.5 application migration process I\'ve discovered an extremely strange behavior. I\'ve been able to track this issue down to this short code snipp

2条回答
  •  攒了一身酷
    2020-12-02 00:45

    So, it's actually a by-design behavior, and if someone has similar issues, here is the code which always outputs the same result:

    const int CXFRAME = 0x20;
    const int CYFRAME = 0x21;
    const int CXPADDEDBORDER = 92;
    
    var dx = GetSystemMetrics(CXFRAME);
    var dy = GetSystemMetrics(CYFRAME);
    var d  = GetSystemMetrics(CXPADDEDBORDER);
    dx += d;
    dy += d;
    
    Console.WriteLine("{0}x{1}", dx, dy);
    Console.ReadKey();
    

    Also note that RibbonWindow WPF control, which uses WindowChrome and now comes as a part of .NET 4.5 does not know about this changes and displays messy window borders (fortunately, I think it can be fixed using modified styles).

提交回复
热议问题