更新: WinFormsのNativeWindowクラスをチェックアウトすることもできます。このクラスを使用して、ネイティブをラップし、HWWNDそのウィンドウに送信されるウィンドウメッセージをリッスンできます。
MoveWindowウィンドウB(ウィンドウB)の位置(および寸法)を設定するには、Win32API関数が必要になると思いますHWND。このAPI関数は、.NETからP/Invokeを介して呼び出すことができます。
GetWindowRectウィンドウBの現在の位置とサイズを取得するには、さらにP/Invokeを介してを呼び出す必要がある場合があります。
次のコードはそのままでは機能しない可能性があり、より簡単な解決策があるかもしれませんが、上記のリンクとともに出発点を提供する可能性があります。
// the following P/Invoke signatures have been copied from pinvoke.net:
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd,
int X, int Y,
int nWidth, int nHeight,
bool bRepaint);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(HandleRef hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
...
System.Windows.Form a = ...;
IntPtr b = ...;
RECT bRect;
GetWindowRect(b, out bRect);
MoveWindow(b,
a.Location.X + 50, b.Location.Y,
bRect.Right - bRect.Left, bRect.Bottom - bRect.Top,
true);