Reputation: 7
I am creating a C# form application. I wanted to show the initial form on a second screen. I want to open the other form pages on the first screen. There is a resolution difference between two screens. How can I show the initial form on the second screen and the other five forms on the main screen?
Upvotes: 0
Views: 3871
Reputation: 105
I've used this method, hope it helps you:
public void MaximizeToMonitor(Form frm, int monitorIndex)
{
try
{
Screen screen = Screen.AllScreens[monitorIndex];
if(screen != null)
{
frm.WindowState = FormWindowState.Normal;
var workingArea = screen.WorkingArea;
frm.Left = workingArea.Left + 10;
frm.Top = workingArea.Top + 10;
frm.Width = workingArea.Width + 10;
frm.Height = workingArea.Height + 10;
frm.WindowState = FormWindowState.Maximized;
}
}
catch (Exception ex)
{
MessageBox.Show($"Monitor does not exists. {Environment.NewLine}{ex.Message}");
}
}
Upvotes: 0
Reputation: 23113
In matter of window positioning there are no "two screens" but just one "working area".
Meaning if you have two FullHD screens next to each other you have a working area of 3840x1080 (minus some for taskbar and such).
If you then place a window at Left = 200
and Top = 100
it will be placed 200 pixels to the left side of the left screen and if you place it at Left = 2120
and Top = 100
it will be placed at the same position on the right screen.
And for all that to work you need to use StartPosition = FormStartPosition.Manual
.
Upvotes: 4