If a Form is a child form, when change the form.location, the value assign to it should be client coordinate??? RRS feed

  • 问题

  • Hi all,

    I met an stranger issue.

    we know that the Form has a property "Location", it representive the screen coordinate....

    no doubt about it.

    However, when we setparent for this window, the condition changed.

    Test sample code:

    //get current location of the form. it will be in screen coordinate.
    Point lOldPt = Location;
    //update this point
    Point lNewPt = new Point(lOldPt.x, lOldPt.y);
    //assign the new point after update to the location property.
    Location = lNewPt;

    After assigned for the Location proptery, we get that the new value for the Location is different from the value lNewPt;

    seem there is a conversion inside the assign operation.

    and the value assign to the Location  should be client coordinate, otherwise, it will not work as you expected.

    This is really strange issue..

    why we need to assign the client coordinate to it. however, if you get it, it will return screen coordinate???

    what doed .net inside done????

    However, if the form is not a child form,  it will worked normally as usually.

    Does anayone can explain on this????

    I am urgent waiting for you....

    Thanks in advance.

    2011年2月22日 4:33


  • This is by design. In Windows, each window must have a parent window, and the location of window is related to its parent window (in client coordinal). You will see the top window works properly, its Location property is screen related not client related because the parent window of top window is desktop, and the desktop window keeps the same location measurement as your primary screen. Concluded from above, windows is hierarchical; there is a top window for all the other windows, and the nested window's location is directly related to its parent's location. Hope this helps. Thanks, Mark.
    Mark Zhou
    • 已标记为答案 Neddy Ren 2011年2月25日 9:15
    2011年2月22日 9:06