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?