I have two displays. I want to make a media player and I want to play video full screen on my secondary display. So I’m trying to make a media player using WPF
Here is the code so far I wrote
Screen[] _screens = Screen.AllScreens; System.Drawing.Rectangle ractagle = _screens[1].Bounds; //player is my window player.WindowState = WindowState.Maximized; player.WindowStyle = WindowStyle.None; player.Left = ractagle.X; player.Top = ractagle.Y; // MediaControl is an media elements MediaControl.Height = ractagle.Height; MediaControl.Width = ractagle.Width;
But somehow it’s just playing on my first display. Any kind of help is very much appreciated.
To open a new window and have it centred on the screen, set the WindowStartupLocation property to CenterScreen. You can do this using the XAML or in code before the window is displayed. Run the program and click the button to see the result.
You will need to create an instance of a new window like so. var window2 = new Window2(); Once you have the instance you can use the Show() or ShowDialog() method depending on what you want to do. var result = window2.
Window is the root control that must be used to hold/host other controls (e.g. Button) as container. Page is a control which can be hosted in other container controls like NavigationWindow or Frame. Page control has its own goal to serve like other controls (e.g. Button). Page is to create browser like applications.
It is the root window of an XAML application which provides minimize/maximize option, Title bar, border, and close button. It also provides the ability to create, configure, show, and manage the lifetime of windows and dialog boxes.
You need to make sure that the WindowStartupLocation
is set to Manual
for the form you are displaying
Otherwise nothing you do will have any effect on the position of the window.
using System.Windows.Forms; // reference System.Drawing // Screen s = Screen.AllScreens[1]; System.Drawing.Rectangle r = s.WorkingArea; Me.Top = r.Top; Me.Left = r.Left;
This header of the XAML of the Window I used.
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="823" WindowStartupLocation="Manual"> <Canvas Width="743"> //Controls etc </Canvas> </Window>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With