开发者

Center window component

开发者 https://www.devze.com 2023-01-28 20:35 出处:网络
I have create a window component but it will randomly position whether I open its window, x and y positions will only offset the elements, not window. How do I position it to the center of the screen?

I have create a window component but it will randomly position whether I open its window, x and y positions will only offset the elements, not window. How do I position it to the center of the screen?

Flex 4 (AS3):

private function开发者_JS百科 openDoc():void {
    if (newWindow != null) newWindow.close();
    newWindow = new docwin();
    newWindow.width = 500;
    newWindow.height = 320;
    newWindow.type = "normal";
    newWindow.systemChrome = "standard";
    newWindow.transparent = false;
    newWindow.setStyle("showFlexChrome", true);
    newWindow.showStatusBar = false;
    newWindow.minimizable = false;
    newWindow.maximizable = false;
    newWindow.resizable = false;
    newWindow.open();
}


Try this:

newWindow.x = Math.ceil((Capabilities.screenResolutionX - newWindow.width) / 2);
newWindow.y = Math.ceil((Capabilities.screenResolutionY - newWindow.height) / 2);


You can use layout property of window like horizontalCentre and verticalCentre use contstraint based layout scheme


You have to position the new window with reference to stageWidth and stageHeight properties.

Assuming the origin of your new window is top left, the new location of the the windows will be:

(Stage.stageWidth - newWindow.width)/2, (Stage.stageHeight - newWindow.height)/2;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号