Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8123493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:11:56+00:00 2026-06-06T06:11:56+00:00

I want my WinForms application to create an instance of itself for each screen

  • 0

I want my WinForms application to create an instance of itself for each screen and display on that screen.
I have the following code:

Main form:

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 form:

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);
        }
    }
}

My application does create a new instance for every screen, however it only displays on my main screen and does not display on the other screens.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:11:57+00:00Added an answer on June 6, 2026 at 6:11 am

    This looks suspect:

    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;
    

    You pass x and y values across on the command line, and then ignore them and use the width and height of the screen to set your x/y values. If all of the screens are the same resolution, and arranged horizontally or vertically, it’s likely that all of these windows are positioned below (or to the right of) any visible portions of the screen.

    I also can’t find any guarantee that Screen.AllScreens will always return the screens in the same order, so the screenNum value may be referencing a different screen.


    I’d also prefer to see this code appearing after the call to InitializeComponents rather than before, so you know that any designer set properties will be overridden by your code, rather than vice versa.


    So, my code is:

    public MainForm()
    {   
        InitializeComponent();
    
        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);
                this.Left = xPos;
                this.Top = yPos;
                this.StartPosition = FormStartPosition.Manual;
            }
        }
    }
    

    And:

    private void TakeOverAllScreens()
    {
        foreach (Screen s in Screen.AllScreens)
        {
            if (s != Screen.PrimaryScreen)
            {
                Process.Start(Application.ExecutablePath, "Screen|" + s.Bounds.X + "|" + s.Bounds.Y);
            }
        }
    }
    

    Of course, the TryParse calls are pointless and can be replaced by Parse, if you’re just going to ignore the return value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a WinForm application that must draw data coming from a
I want to link my winforms application to Facebook fanpage,So that a +1 is
In a WinForms application, I want to provide visual feedback that a looping background
I have a C# winforms application with a sql server backend and want to
I want to create a simple 3D line in a WinForms application to improve
I have an NumericTextBox component that extends an TextBox in my WinForms application. To
I create a treeview with several nodes in a WinForms application. I want to
I am developing a winforms application and I have a scenario where I want
I am creating a winforms application.I want to create a installer program for installing
I want to create logins & users for my c#.net winforms application which uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.