/// <summary> /// 화면(모니터) 번호를 구한다.-현재 마우스 위치 기준 /// </summary> /// <returns></returns> public static int ScreenNumGet() { api.POINT pnt = new api.POINT(); api.GetCursorPos(ref pnt); return(ScreenNumGet(pnt.X, pnt.Y)); }
/// <summary> /// 폼의 위치를 조정 하여 준다. /// </summary> /// <param name="frm"></param> /// <param name="type">조정할 기준 타입</param> public static void From_PositionSet(Form frm, Function.form.enFormPositionType type) { int x = 0; int y = 0; //기준 위치 int cX = 0; int cY = 0; try { switch (type) { case enFormPositionType.MousePosition_Center: api.POINT pnt = new api.POINT(); api.GetCursorPos(ref pnt); x = pnt.X - (frm.Width / 2); y = pnt.Y - (frm.Height / 2); cX = pnt.X; cY = pnt.Y; break; } int scrNo = ScreenNumGet(cX, cY); //스크린 밖으로 창이 나가 지 않도록 if (scrNo >= 0) { Screen scr = Screen.AllScreens[scrNo]; if (x < scr.Bounds.Left) { x = scr.Bounds.Left; } else if ((x + frm.Width) > scr.Bounds.Right) { x = scr.Bounds.Right - frm.Width; } if (y < scr.Bounds.Top) { y = scr.Bounds.Top; } else if ((y + frm.Height) > scr.Bounds.Bottom) { y = scr.Bounds.Bottom - frm.Height; } } frm.Left = x; frm.Top = y; } catch { } }