移动窗体

        [DllImport("user32.dll")]
public static extern IntPtr FindWindow(IntPtr sClassName, string sWindowName);

[DllImport(
"user32.dll")]
public static extern bool MoveWindow(IntPtr Window, int x, int y, int w, int h, bool rePaint);

 

使用FindWindow得到需要移动的窗体的句柄

使用MoveWindow改变窗体的位置、大小

 

例子:

        private void button3_Click(object sender, EventArgs e)
{
IntPtr aa
= FindWindow(IntPtr.Zero, textBox1.Text.Trim());
this.Text = aa.ToInt32().ToString();
if (aa != IntPtr.Zero)
{
bool b = MoveWindow(aa, 300, 300, 300, 300, false);
}
}

你可能感兴趣的:(移动)