[팁] C# 듀얼모니터에서 현재 실행된 위치에서 새창열기
듀얼모니터에서 예를들면 서브 모니터에서 실행파일을 실행하고 난뒤 서브 폼도 서브 모니터에서 열고 싶을때가 있다.
즉, 실행 파일의 현재 위치에 따라서 서브 폼이 열리도록 하는것!.
먼저 Form1
private void GetCurrentMonitor()
{
Screen[] screens = Screen.AllScreens;
int Tmp; <--- Form간에 데이터 교환을 위해 선언한 변수
if (screens.Length > 1) // Has more screen
{
if (screens[0].WorkingArea.Contains(this.Location)) <-- 현재 실행파일 위치가 어딘지 찾는다.
{
Tmp = 0;
}
else
{
Tmp = 1;
}
Form2.MonitorStatus = Tmp; <--Form2로 현재 실행파일위치에 대한 모니터 위치를 보내준다.
}
}
Form2
Screen[] screens = Screen.AllScreens;
if (screens.Length > 1) // Has more screen
{
Screen scrn = null;
if (MonitorStatus == 0) <-- Form1으로 부터받은 실행파일의 위치
{
scrn = screens[0];
}
else
{
scrn = screens[1];
}
Location = new System.Drawing.Point(scrn.Bounds.Left, 0); <--Form2를 로드한다.
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
}