Нахождение монитора заказа - PullRequest
0 голосов
/ 09 января 2019

Как показано на рисунке. Я могу найти основной монитор с библиотекой экрана. Но однажды я также хотел бы найти порядок монитора. Я пытаюсь сделать что-то вроде заставки.

Display Options

Сначала 1 монитор (являющийся основным монитором) будет слева, а второй - справа. Но если я изменю порядок 2 -> 1 .. основной монитор будет справа. И форма, которую я сделал, уйдет в другие неожиданные моменты. Есть ли способ обнаружить это изменение порядка? Прямо сейчас мой код такой.

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