1

I'm making a simple program in C# .NET-Framework, and for sound I'm using the (WPF-component) MediaPlayer (because of the many benefits over SoundPlayer). But when I'm using the dedicated code in my program, it rescales the forms (makes it atleast 30% smaller), making the text unreadable and the form visually unusable.

These are my settings for my Form:

Non-sizable
Custom minimize and close buttons
Size: 1150 x 800
Form borderstyle: None

And this is the code that I'm using to play sound (simplified):

using System.Reflection; // for URI code
using System.IO; // for URI code
using System.Windows.Media;

string soundURI = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Click1.wav"); //gets the sound URI  
MediaPlayer sound = new MediaPlayer();

private void Button1_Click(object sender, EventArgs e)  
{  
    sound.Open(new Uri(soundURI));  
    sound.Play();  
}

When I run the code, my form automatically resizes to something smaller than 1150 x 800, but it does not update the this.Width or this.Height, so it's only visual. When I exclude the usage of MediaPlayer, the form size acts how it's supposed to act.

I now know that it's the MediaPlayer that causes this problem. Not using MediaPlayer would be the last option, but I could not find a fix for this problem online, and I don't know what's causing this behaviour (from MediaPlayer). What might be causing this?

halfer
  • 19,824
  • 17
  • 99
  • 186
thim24
  • 624
  • 1
  • 5
  • 14
  • 2
    [DPI Awareness](https://stackoverflow.com/questions/50239138/dpi-awareness-unaware-in-one-release-system-aware-in-the-other/50276714#50276714) – stuartd Jun 29 '20 at 16:02
  • I created a MediaPlayer in my test, but it works fine and not resizes the form. The size is always maintained at 1150, 800. To reproduce the issue, did you miss some steps? – 大陸北方網友 Jun 30 '20 at 01:48
  • 1
    [DPI Awareness - Unaware in one Release, System Aware in the Other](https://stackoverflow.com/a/50276714/7444103). If you don't want to make your app DpiAware, the counter-measure is the code snippet in the last line. – Jimi Jun 30 '20 at 02:57

0 Answers0