如何使窗口自动居中?

来源:互联网 发布:淘宝鹊桥是什么 编辑:程序博客网 时间:2024/05/21 14:02

问:我想使应用程序的主窗口自动显示在屏幕的中心而不管屏幕的分辨率、操作系统版本如何改变,这该怎么办呢?

答:It's too easy ……

原理:利用PB中的Environment对象和窗口的Move函数。

窗口(w_main)代码如下:

    //变量声明
    Environment env_system

   
Integer int_scrwidth,int_scrheight

    //关闭窗口刷新
    SetRedraw(False)

    //获得屏幕的宽度和高度
    GetEnvironment(env_system)
    int_scrwidth=PixelsToUnits(env_system.screenwidth,xpixelstounits!)
    int_scrheight=PixelsToUnits(env_system.screenheight,ypixelstounits!)
    //移动窗口到屏幕中心
    move((int_scrwidth - this.width)/2,(int_scrheight - this.height)/2)
    //打开窗口刷新
    SetRedraw(True)

原创粉丝点击