public static void RestoreFormPlacement(RegistryKey key, Form form, string name)
        {
            Rectangle? rect = key.GetRectangleValue(name);

              if (rect.HasValue)
              {
            Rectangle formBounds = rect.Value;

            if (!form.IsMdiChild)
            {
              formBounds = EnsureFitsInDesktop(formBounds);
            }

            form.WindowState = FormWindowState.Normal;
            form.SetDesktopBounds(formBounds.X, formBounds.Y, formBounds.Width, formBounds.Height);
              }

              FormWindowState? state = key.GetWindowStateValue(name);

              if (state.HasValue)
              {
            form.WindowState = state.Value;
              }
        }