移动窗体

        [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);
}
}

posted @ 2011-09-19 11:41  Mo  阅读(208)  评论(0编辑  收藏  举报