1
我希望我的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);
}
}
}
我的應用程序,爲每個畫面創建一個新的實例,但它只是我的主屏幕上顯示並不顯示在其他屏幕上。
太棒了!有用! :d。我認爲這個問題試圖指定屏幕。 'this.Left = sc [screenNum] .Bounds.Width;'而不是僅僅使用'this.Left = xPos;'謝謝你! –