同时移动2个表格 [英] Moving 2 forms at the same time
本文介绍了同时移动2个表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里有点卡住了.我正在尝试同时移动2个表单,而不使用OnMove,LocationChanged,Docking等.
I'm stuck a little bit here. I'm trying to move 2 forms at the same time without using OnMove, LocationChanged, Docking etc.
与其位置进行交互的唯一方法是覆盖WndProc.可能有帮助的是,表单A是表单B的所有者.因此,每当移动A时,我也要移动B.不是到相同的位置,而是到相同的距离.
The only way to interact with their locations is to override WndProc. Something which might be helpful is that form A is owner of form B. So whenever A is moved I want to move B as well. Not to the same location but the same distance.
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0084)
{
Form[] temp = this.OwnedForms;
if(temp.Length > 0)
{
/* moving temp[0] to the same ratio as this form */
}
m.Result = (IntPtr)2;
return;
}
base.WndProc(ref m);
}
A和B具有相同的WndProc,因为它们是同一类的2个对象.
Both A and B have the same WndProc since they are 2 objects from the same class.
推荐答案
我设法解决了这个问题:
I managed to solve the problem:
protected override void WndProc(ref Message m)
{
Form temp = this.Owner;
if (m.Msg == 0x0084)
{
m.Result = (IntPtr)2;
return;
}
if (m.Msg == 0x0216 && temp != null)
{
if (!movedonce)
{
oldlocationx = this.Location.X;
oldlocationy = this.Location.Y;
movedonce = true;
}
temp.Location = new Point(temp.Location.X + this.Location.X - oldlocationx, temp.Location.Y + this.Location.Y - oldlocationy);
oldlocationx = this.Location.X;
oldlocationy = this.Location.Y;
}
base.WndProc(ref m);
}
这篇关于同时移动2个表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文