.Net Framework Standard/WindowsApplication
C# Winform - 마우스 포인터가 있는 모니터에 Form 열기
달빛에취하다
2024. 1. 5. 09:45
다중 모니터 사용시 주 모니터 쪽에서 응용프로그램이 시작되며 Form이 열리는 것이 불편할 수 있어 사용.
private static void SetStartPosition(Form frm)
{
frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromPoint(System.Windows.Forms.Cursor.Position);
System.Drawing.Rectangle rectangle = screen.WorkingArea;
var d = screen.WorkingArea.Location;
frm.Left = d.X + (rectangle.Width / 2 - frm.Width / 2);
frm.Top = d.Y + (rectangle.Height / 2 - frm.Height / 2);
}