DeepOceanDream 2017-08-09 03:56 采纳率: 100%
浏览 2185
已采纳

C# WPF 无框架窗体前端或后台设置居中都无效,请问各位大虾

前端: WindowStartupLocation="CenterScreen"
后台: WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;//屏幕居中设置失败,未解决
但是运行的时候还是不能居中显示,求大虾解答

  • 写回答

1条回答 默认 最新

  • 战在春秋 2017-08-09 05:34
    关注

    检查窗体的height和width属性是否忘记设置,如果仍然未能解决问题,
    可以在合适的位置调用如下函数:

    private void CenterWindowOnScreen()
    {
        double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
        double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
        double windowWidth = this.Width;
        double windowHeight = this.Height;
        this.Left = (screenWidth / 2) - (windowWidth / 2);
        this.Top = (screenHeight / 2) - (windowHeight / 2);
    }
    

    如果对您有帮助,请采纳答案好吗,谢谢!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?