문제

다음과 같이 보조 모니터에서 Windows 양식을 설정하려고합니다.

private void button1_Click(object sender, EventArgs e)
{
    MatrixView n = new MatrixView();
    Screen[] screens = Screen.AllScreens;
    setFormLocation(n, screens[1]);
    n.Show();
}

private void setFormLocation(Form form, Screen screen)
{
    // first method
    Rectangle bounds = screen.Bounds;
    form.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);

    // second method
    //Point location = screen.Bounds.Location;
    //Size size = screen.Bounds.Size;

    //form.Left = location.X;
    //form.Top = location.Y;
    //form.Width = size.Width;
    //form.Height = size.Height;
}

경계의 속성은 올바른 것처럼 보이지만, 내가 시도한 두 가지 방법 모두에서는 기본 모니터의 양식을 최대화합니다. 어떤 아이디어?

도움이 되었습니까?

해결책

setformlocation 메소드 내부에서 WindowStartUplocation 매개 변수를 "매뉴얼"으로 설정하십시오.

다른 팁

this.Location = Screen.AllScreens[1].WorkingArea.Location;

이것은 형식 참조입니다.

@Gengi의 대답은 간결하고 잘 작동합니다. 창이 최대화되면 창을 움직이지 않습니다. 이 스 니펫은 (Windows가 "정상적인"치수가 새로운 화면 치수보다 작아야한다고 생각하지만 :

    void showOnScreen(int screenNumber)
    {
        Screen[] screens = Screen.AllScreens;

        if (screenNumber >= 0 && screenNumber < screens.Length)
        {
            bool maximised = false;
            if (WindowState == FormWindowState.Maximized)
            {
                WindowState = FormWindowState.Normal;
                maximised = true;
            }
            Location = screens[screenNumber].WorkingArea.Location;
            if (maximised)
            {
                WindowState = FormWindowState.Maximized;
            }
        }
    }

확실합니까 screens[1] 당신의 이차적입니까? 주다 screens[0] 시도. 코드는 기본적으로 정확합니다.


좋아, 확인했는데, 쇼 () 이후에해야 할 것입니다.

n.Show();
setFormLocation(n, screens[1]);

원치 않는 깜박임을 제공합니다. 그러나 당신은 아마 할 수 있습니다 :

n.SetBounds(-100, -100, 10, 10);  // or similar
n.Show();
setFormLocation(n, screens[1]);

XNA 4 듀얼 화면 응용 프로그램에 이것을 사용했습니다 (전체 화면 XNA 게임 창 + winform)

form_load () 메소드에서 다음 코드를 배치합니다.

var primaryDisplay = Screen.AllScreens.ElementAtOrDefault(0);  
var extendedDisplay = Screen.AllScreens.FirstOrDefault(s => s != primaryDisplay) ?? primaryDisplay;

this.Left = extendedDisplay.WorkingArea.Left + (extendedDisplay.Bounds.Size.Width / 2) - (this.Size.Width / 2);
this.Top = extendedDisplay.WorkingArea.Top + (extendedDisplay.Bounds.Size.Height / 2) - (this.Size.Height / 2);

보조 화면에 양식을 표시하려면 :

    Screen primaryFormScreen = Screen.FromControl(primaryForm);
    //Use this if you are looking for secondary screen that is not primary
    Screen secondaryFormScreen = Screen.AllScreens.FirstOrDefault(s => !s.Primary) ?? primaryFormScreen;
    //Use this if you are looking for screen that is not being used by specific form
    Screen secondaryFormScreen = Screen.AllScreens.FirstOrDefault(s => !s.Equals(primaryFormScreen)) ?? primaryFormScreen;
    //Putting the form on the other screen
    secondaryForm.Left = secondaryFormScreen.Bounds.Width;
    secondaryForm.Top = secondaryFormScreen.Bounds.Height;
    //Recommended to use, You can change it back later to the settings you wish
    secondaryForm.StartPosition = FormStartPosition.Manual;
    secondaryForm.Location = secondaryFormScreen.Bounds.Location;
    Point p = new Point(secondaryFormScreen.Bounds.Location.X, secondaryFormScreen.Bounds.Location.Y);
    secondaryForm.Location = p;
    secondaryForm.Show();

특정 화면을 기대하고 있다면 "Screen.AllScreens"에서 루프를하고 위의 프로세스를 사용할 수 있습니다.

양식 시작 위치 속성을 매뉴얼로 설정하십시오

    public void MoveWindowToProjector ()  
    { 
           Rectangle rectMonitor;

            // Create New Process
            Process objProcess = new Process();

            //Get All the screens associated with this Monitor
            Screen[] screens = Screen.AllScreens;

            // Get Monitor Count
            int iMonitorCount = Screen.AllScreens.Length;

            // Get Parameters of Current Project
            string[] parametros = Environment.GetCommandLineArgs();
           // if (parametros.Length > 0)
           // {
                //objProcess.StartInfo.FileName = parametros[0];
               // objProcess.Start();
          //  }
            // Get Window Handle of this Form
            IntPtr hWnd = this.Handle;

            Thread.Sleep(1000);


            if (IsProjectorMode)
            {
                if (iMonitorCount > 1) // If monitor Count 2 or more
                {
                    //Get the Dimension of the monitor
                    rectMonitor = Screen.AllScreens[1].WorkingArea;
                }
                else
                {
                    //Get the Dimension of the monitor
                    rectMonitor = Screen.AllScreens[0].WorkingArea;
                }

            }
            else
            {
                rectMonitor = Screen.AllScreens[0].WorkingArea;

            }
            if (hWnd != IntPtr.Zero)
            {
                SetWindowPos(hWnd, 0,
                    rectMonitor.Left, rectMonitor.Top, rectMonitor.Width,
                    rectMonitor.Height, SWP_SHOWWINDOW);
            }

        }
  Screen[] screens = Screen.AllScreens;
                sc aoc = new sc();
                aoc.Show();
    aoc.Location = Screen.AllScreens[INDEX OF YOUR AVAILABLE SCREENS TARGET].WorkingArea.Location;

최대화 된 창 상태의 경우

aoc.WindowState = FormWindowState.Maximized;

모든 x, y 위치

aoc.Location = new Point(TARGET X POSITION, TARGET Y POSITION);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top