in Education by
Hello fellow developers I have a little question. I have a problem that's starting to annoy me. I have written a program in C# which opens the Chrome Browser. However, the Chrome Browser always opens at the place where it was last opened. Is there a possibility to put the browser window directly on the second screen at every start? My goal is that the Chrome Browser always starts automatically on the other screen. Anybody got an idea? Thank you JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You could try the following: using System; using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; ........................... public void StartChrome() { var allScreens = Screen.AllScreens.ToList(); var screenOfChoice = allScreens[1]; // repllace with your own logic var chromeProcess = new Process { StartInfo = { Arguments = "https://www.google.com --new-window --start-fullscreen", FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", WindowStyle = ProcessWindowStyle.Normal } }; chromeProcess.Start(); // Needed to move the the process. Thread.Sleep(1000); // setting the x value here can help you determmine which screen to move the process to // 0 will be the first screen, and the '.WorkingArea.Right' value to the previous screen's '.WorkingArea.Right' would change which // screen to display it on. MoveWindow(chromeProcess.MainWindowHandle, screenOfChoice.WorkingArea.Right, screenOfChoice.WorkingArea.Top, screenOfChoice.WorkingArea.Width, screenOfChoice.WorkingArea.Height, false); } [DllImport("user32.dll", SetLastError = true)] internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); EDIT: Just to explain further, if you have 3 screens with a resolution of 1920x1080 setting the x parameter in the MoveWindow() method will place the window at the left most place of the first screen, setting the x parameter to 1920 will place the application on the second screen, setting the x parameter to 3840 the process would be on the third screen. With having access to all the screens and their widths, you should be able to accurately place the process on the screen of choice almost all the time unless a user has custom ordering of their multi screen layout, then I'm not 100% sure if this would be ideal. EDIT 2: The above code will not work on .NetCore 2.2 and lower as it uses System.Windows.Forms which I believe will only be introduced in .NetCore 3.0

Related questions

0 votes
    clicking the_____button enlarges the application window to fill the whole screen Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    Way to clear screen in MySQL in Window operating system?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    _____ is the concept in which a process is copied into the main memory from the secondary memory according to the ... a) Paging b) Demand paging c) Segmentation d) Swapping...
asked Oct 27, 2022 in Education by JackTerrance
0 votes
    निम्नलिखित में से कौन माध्यमिक (secondary) भंडारण उपकरण का उदाहरण नहीं है? Hard disks (हार्डडिस्क) RAM (रैम) Magnetic ... ) CD(सी डी) Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    1. Primary memory is called memory. 2. The full form of OMR is 3. Secondary memory of a computer is also ... 5 memory is volatile. Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    Main memory is also known as __ memory? (a) Secondary memory (b) Auxiliary memory (c) Primary memory (d) None of the above Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    which of the following statement is false a secondary storage of non-volatile B primary storage is volatile C when ... of the above Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    What is the role of secondary storage in a computer? How it is different from primary memory? Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    Which one of the following would not be considered as a form of secondary storage? (a) Floppy Disk (b) Optical ... Drive (e) Hard Disk Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    Which of the following is not a secondary storage device? * CD DVD Hard disk ROM Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    Is a secondary consumer. (a) Grasshopper (b) Elephant (c) Frog (d) Human Select the correct ... Science,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    Tiger is a /an (a) Producer (b) Primary consumer (c) Apex consumer (d) Secondary consumer ... Science,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    Carnivores feed upon (a) Decomposers (b) Herbivores (c) Producers (d) Secondary producers Select ... Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    After the death of apex consumers, energy becomes available to (a) Primary consumer (b) Secondary ... ,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    Find out the correlation: 1. Grasshopper : Primary consumer :: Tiger : .. 2. Owl ... Science,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
...