WinForm 分屏显示,父窗体点击分屏按钮后子窗体在第二屏幕上显示
主窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.FormBorderStyle = FormBorderStyle.None;
form.Show();
}
}
}
子窗体(分屏窗体)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
SetFullScreenToSecondMonitor(this);
}
private void SetFullScreenToSecondMonitor(Form form)
{
Screen[] screens = Screen.AllScreens;
if (screens.Length > 1)
{
Rectangle secondMonitorBounds = screens[1].Bounds;
form.Location = new Point(secondMonitorBounds.Left, secondMonitorBounds.Top);
form.Size = new Size(secondMonitorBounds.Width, secondMonitorBounds.Height);
}
}
}
}