2 using System.Collections.Generic;
10 public static class FormExtensions
12 public static void CenterFormOnMouse(
this Form Form)
15 Point MousePos = Cursor.Position;
16 Rectangle R = Screen.FromPoint(MousePos).WorkingArea;
18 int X = (Cursor.Position.X - Form.Width / 2);
19 int Y = (Cursor.Position.Y - Form.Height / 2);
22 X = X.Limit(R.Left+10, (R.Right - Form.Width-10).Limit(0,R.Right-10));
23 Y = Y.Limit(R.Top+10, (R.Bottom - Form.Height-10).Limit(0,R.Bottom-10));
26 Form.SetDesktopLocation(X, Y);