参照の追加
「参照の追加」→「アセンブリ」で下記の参照を追加する。
- System.Windows.Forms
- System.Drawing
ソース
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Forms;
namespace DualMonitor2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
const int MONITOR1 = 0;
const int MONITOR2 = 1;
if (Screen.AllScreens.Length < 2)
{
Console.WriteLine("Not Multi Monitors!");
}
else
{
Screen Screen1 = Screen.AllScreens[MONITOR1];
Screen Screen2 = Screen.AllScreens[MONITOR2];
var bounds1 = Screen1.Bounds;
Window window2 = new Window
{
Background = new SolidColorBrush(Colors.Red),
WindowStartupLocation = WindowStartupLocation.Manual,
WindowState = WindowState.Normal,
WindowStyle = WindowStyle.None,
Left = bounds1.Left,
Top = bounds1.Top,
Width = bounds1.Width,
Height = bounds1.Height
};
window2.Show();
window2.WindowState = WindowState.Maximized;
var bounds2 = Screen2.Bounds;
Window window3 = new Window
{
Background = new SolidColorBrush(Colors.Blue),
WindowStartupLocation = WindowStartupLocation.Manual,
WindowState = WindowState.Normal,
WindowStyle = WindowStyle.None,
Left = bounds2.Left,
Top = bounds2.Top,
Width = bounds2.Width,
Height = bounds2.Height
};
window3.Show();
window3.WindowState = WindowState.Maximized;
}
}
}
}