■ Screen 클래스의 AllScreens 정적 속성을 사용해 다른 모니터에서 폼을 표시하는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using System; using System.Drawing; using System.Windows.Forms; namespace TestProject { public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.testButton.Click += testButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 테스트 버튼 클릭시 처리하기 - testButton_Click(sender, e) /// <summary> /// 테스트 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void testButton_Click(object sender, EventArgs e) { Screen[] screenArray = Screen.AllScreens; if(screenArray.Length > 1) { Screen screen = (screenArray[0].WorkingArea.Contains(Location)) ? screenArray[1] : screenArray[0]; Form form = new Form(); form.Show(); // Show 메소드와 속성 설정의 순서가 중요하다. form.Location = new Point(screen.Bounds.Left, 0); form.WindowState = FormWindowState.Maximized; } } #endregion } } |