As shown in the picture. I can find the primary monitor with the Screen library. But once I would also like to find the ordering of the monitor. What I'm trying to make is something like a screensaver.
At first the 1 monitor(which is the primary monitor) will be at the left and the 2nd monitor will be at right. But if I change the order 2 -> 1 .. the primary monitor will be at the right. And the form that I made will go in other unexpected points. Is there anyway to detect this change of order???? Right now my code is this.
private void ResizeScreen()
{
// 전체 화면으로 사이즈 설정
int form_width = 0;
int form_height = 0;
int form_x = 0;
int form_y = 0;
int sub_screen_width = 0;
int sub_screen_height = 0;
foreach (Screen screen in Screen.AllScreens)
{
form_width += screen.Bounds.Width;
NLog.LogManager.GetCurrentClassLogger().Trace("form_width : " + form_width);
form_height += screen.Bounds.Height;
NLog.LogManager.GetCurrentClassLogger().Trace("form_height : " + form_height);
if (form_x > screen.Bounds.X)
form_x = screen.Bounds.X;
if (form_y > screen.Bounds.Y)
form_y = screen.Bounds.Y;
//form_x = Math.Abs(form_x);
NLog.LogManager.GetCurrentClassLogger().Trace("form_x : " + screen.Bounds.X);
NLog.LogManager.GetCurrentClassLogger().Trace("form_y : " + screen.Bounds.Y);
if (screen.Bounds.X < 0)
sub_screen_width += screen.Bounds.Width;
if (screen.Bounds.Y < 0)
sub_screen_height += screen.Bounds.Height;
}
this.Width = form_width;
this.Height = form_height;
this.CenterToScreen();
this.Location = new Point(form_x, form_y);
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate
{
NLog.LogManager.GetCurrentClassLogger().Trace("PrimaryScreen : " + Screen.PrimaryScreen.Bounds.Width + ", " + Screen.PrimaryScreen.Bounds.Height);
mainPanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
mainPanel.Visible = true;
NLog.LogManager.GetCurrentClassLogger().Trace("MainPanel : " + (Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X + ", " + (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
approvalRequestPanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - approvalRequestPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - approvalRequestPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
approvalRequestPanel.Visible = false;
NLog.LogManager.GetCurrentClassLogger().Trace("approvalRequestPanel : " + (Screen.PrimaryScreen.Bounds.Width - approvalRequestPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X + ", " + (Screen.PrimaryScreen.Bounds.Height - approvalRequestPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
meetingTextPanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - meetingTextPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - meetingTextPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
meetingTextPanel.Visible = false;
NLog.LogManager.GetCurrentClassLogger().Trace("meetingTextPanel : " + (Screen.PrimaryScreen.Bounds.Width - meetingTextPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X + ", " + (Screen.PrimaryScreen.Bounds.Height - meetingTextPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
approvalpopuppanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
approvalpopuppanel.Visible = false;
meetingpopuppanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
meetingpopuppanel.Visible = false;
pc_off_panel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
pc_off_panel.Visible = false;
}));
}
else
{
NLog.LogManager.GetCurrentClassLogger().Trace("PrimaryScreen2 : " + Screen.PrimaryScreen.Bounds.Width + ", " + Screen.PrimaryScreen.Bounds.Height);
mainPanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
mainPanel.Visible = true;
NLog.LogManager.GetCurrentClassLogger().Trace("MainPanel2 : " + (Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X + ", " + (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
approvalRequestPanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - approvalRequestPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - approvalRequestPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
approvalRequestPanel.Visible = false;
NLog.LogManager.GetCurrentClassLogger().Trace("approvalRequestPanel2 : " + (Screen.PrimaryScreen.Bounds.Width - approvalRequestPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X + ", " + (Screen.PrimaryScreen.Bounds.Height - approvalRequestPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
meetingTextPanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - meetingTextPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - meetingTextPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
meetingTextPanel.Visible = false;
NLog.LogManager.GetCurrentClassLogger().Trace("meetingTextPanel2 : " + (Screen.PrimaryScreen.Bounds.Width - meetingTextPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X + ", " + (Screen.PrimaryScreen.Bounds.Height - meetingTextPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
approvalpopuppanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
approvalpopuppanel.Visible = false;
meetingpopuppanel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
meetingpopuppanel.Visible = false;
pc_off_panel.Location = new Point((Screen.PrimaryScreen.Bounds.Width - mainPanel.Bounds.Width) / 2 + Screen.PrimaryScreen.Bounds.X, (Screen.PrimaryScreen.Bounds.Height - mainPanel.Bounds.Height) / 2 + Screen.PrimaryScreen.Bounds.Y);
pc_off_panel.Visible = false;
}
}