none
winform应用,运行在win10系统125%缩放的界面上,当创建System.Windows.Media.MediaPlayer时,窗体会重绘变小 RRS feed

  • 问题

  • winform应用,运行在win10系统125%缩放的界面上,当创建System.Windows.Media.MediaPlayer时,窗体会重绘变小;

    在StackOverflow上发现了14年的提问,请问现在是否有更好的方式解决?

    https://stackoverflow.com/questions/20926549/mediaelement-mediaplayer-classes-break-dpi-virtualization-on-windows-forms-app?r=SearchResults

    2021年7月27日 10:52

全部回复

  • 你好,

    根据我的测试,我发现并没有重现你的问题,在我创建了System.Windows.Media.MediaPlayer后,即使我把系统缩放到125%的界面上,窗体只会自适应变大,这是正常的。

    你可以提供下相关截图吗,以便于我们能够分析你的问题。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2021年7月28日 8:36
    版主
  • 你好,感谢回答

    关于该情况,已经使用提问中提到的解决办法处理了。

    具体问题效果是应该最大化的窗体只显示在屏幕的左上角。

    示例代码:

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                WindowState = FormWindowState.Maximized;
    
                Task.Factory.StartNew(() => { new System.Windows.Media.MediaPlayer(); });
            }
            public override Size MaximumSize
            {
                get
                {
                    return new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
                }
                set
                {
                    base.MaximumSize = value;
                }
            }
        }



    2021年7月28日 9:56
  • 上面的回答是重现问题的代码;

    解决方案是

    Add this assembly attribute to AssemblyInfo.cs

    [assembly: System.Windows.Media.DisableDpiAwareness]

    2022年1月13日 2:10