private void SaveWindowSize(Window wnd) { var info = new NativeMethods.WINDOWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); NativeMethods.GetWindowInfo((new WindowInteropHelper(wnd)).Handle, ref info); savedWidth = info.rcWindow.Right - info.rcWindow.Left; savedHeight = info.rcWindow.Bottom - info.rcWindow.Top; }
public static void SetPosition(string name, int x, int y) { IntPtr hWind = NativeMethods.FindWindow(null, name); NativeMethods.WINDOWINFO info = new NativeMethods.WINDOWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); NativeMethods.GetWindowInfo(hWind, ref info); NativeMethods.SetWindowPos(hWind, (IntPtr)null, x, y, info.rcWindow.Size.Width, info.rcWindow.Size.Height, 0u); }
public static void SetPositionSize(string name, int x, int y, int width, int height) { IntPtr hWind = NativeMethods.FindWindow(null, name); NativeMethods.WINDOWINFO info = new NativeMethods.WINDOWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); NativeMethods.GetWindowInfo(hWind, ref info); do { NativeMethods.SetWindowPos(hWind, (IntPtr)null, x, y, width, height, 0u); info.cbSize = (uint)Marshal.SizeOf(info); NativeMethods.GetWindowInfo(hWind, ref info); } while (info.rcWindow.Size.Height != height && info.rcWindow.Location.Y != y); }