我希望我的 WinForms 应用程序为每个屏幕创建一个自身的实例并在该屏幕上显示。我有以下代码:
主要形式:
class MainForm
{
public MainForm()
{
string[] args = Environment.GetCommandLineArgs();
foreach (string arg in args)
{
if (arg == "TakeOverAllScreens") { TakeOverAllScreens(); }
if (arg.StartsWith("Screen|"))
{
string[] s;
s = arg.Split('|');
int xPos , yPos, screenNum ;
int.TryParse(s[1], out xPos);
int.TryParse(s[2], out yPos);
int.TryParse(s[3], out screenNum);
Screen[] sc;
sc = Screen.AllScreens;
this.Left = sc[screenNum].Bounds.Width;
this.Top = sc[screenNum].Bounds.Height;
this.StartPosition = FormStartPosition.Manual;
}
}
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
}
TakeOverAllScreens 表单:
private void TakeOverAllScreens()
{
int i = 0;
foreach (Screen s in Screen.AllScreens)
{
if (s != Screen.PrimaryScreen)
{
i++;
Process.Start(Application.ExecutablePath, "Screen|" + s.Bounds.X + "|" + s.Bounds.Y+"|" + i);
}
}
}
我的应用程序确实为每个屏幕创建了一个新实例,但是它只显示在我的主屏幕上,而不会显示在其他屏幕上。