当前位置: 代码迷 >> PB >> 怎么让窗口的居中控件在窗口最大化以后依旧居中
  详细解决方案

怎么让窗口的居中控件在窗口最大化以后依旧居中

热度:74   发布时间:2016-04-29 08:41:46.0
如何让窗口的居中控件在窗口最大化以后依旧居中?
我拉了一个一般大小的窗口,里面放置了一些控件,比方数据窗口dw-1.固定了位置,而且是居中的,打开的方式normal

现在我最大化窗口,这样数据窗口就跑到屏幕左上角去了

有没有这样一个通用代码,让这些控件位置在窗口最大化以后,依旧保留原来的居中?

这个跟分辨率没有关系

------解决方案--------------------
探讨

引用:

最好有类似的通用代码,是不是大家没有涉及到这个问题?

通用代码倒是没有,不过有通用的思路就是假如你要让一个名为dw_1的控件在窗口居中可以在窗口的resize事件中写:
--------------------------------
dw_1.x = (NewWidth - dw_1.Width) / 2
dw_1.y = (Ne……

------解决方案--------------------
探讨
最好有类似的通用代码,是不是大家没有涉及到这个问题?

------解决方案--------------------
探讨
引用:
http://www.hur.cn/Soft/2009/3584.html,华软上的,也不知道是不是我上次看到的那个。


这个下载的已经不能正常解压了

------解决方案--------------------
C# code
$PBExportHeader$w_autosize.srw$PBExportComments$自动调节窗口,具有自动居中功能forwardglobal type w_autosize from windowend typetype struct_consize from structure within w_autosizeend typeend forwardtype struct_consize from structure    real        s_conx[]    real        s_cony[]    real        s_conh[]    real        s_conw[]end typeglobal type w_autosize from windowinteger x = 1056integer y = 484integer width = 2638integer height = 1536boolean titlebar = truestring title = "Untitled"boolean controlmenu = trueboolean minbox = trueboolean maxbox = trueboolean resizable = truelong backcolor = 67108864end typeglobal w_autosize w_autosizetype variablesinteger    ii_orgwidth,ii_orgheightcheckbox                          icbx_objradiobutton                        irb_objcommandbutton                icb_objdatawindow                      idw_objdropdownlistbox                iddlb_objdropdownpicturelistbox     iddplb_objeditmask                            iem_objgroupbox                           igb_objhscrollbar                           ihsb_objline                                     iln_objlistbox                                 ilb_objlistview                               ilv_objmultilineedit                        imle_objpicture                                ip_objpicturebutton                      ipb_objpicturelistbox                       iplb_objsinglelineedit                       isle_objtab                                      it_objtreeview                             itv_objuserobject                          iuo_objvscrollbar                           ivsb_objgraph                                 igr_objolecontrol                           iole_objrichtextedit                         irte_objstatictext                            ist_objstatichyperlink                              ishl_objinteger v_li=1integer v_lj=1private:struct_consize s_consizeend variablesforward prototypespublic function integer uf_position (windowobject v_winobj, long ll_width, long ll_height)public function integer uf_resize (windowobject v_winobj, long ll_width, long ll_height)end prototypespublic function integer uf_position (windowobject v_winobj, long ll_width, long ll_height);DragObject dragcontrolLine line_contrOval oval_contrRectangle rect_contrRoundRectangle roun_contrTab l_tabUserobject luo_controlChoose Case v_winobj.typeof()    Case commandbutton!,picturebutton!,checkbox!,radiobutton!, &         statictext!,staticHyperLink!,picture!, &          pictureHyperLink!,groupbox!,singlelineedit!,editmask!, &          multilineedit!,richtextedit!,hscrollbar!,Vscrollbar!, &          Htrackbar!,VtrackBar!,HprogressBar!,VprogressBar!, &          dropdownlistbox!,dropdownpicturelistbox!,listbox!, &          picturelistbox!,listview!,treeview!,datawindow!, &          graph!,olecontrol!                         dragcontrol=v_winobj             s_consize.s_conx[v_li]=dragcontrol.x/ll_width            s_consize.s_cony[v_li]=dragcontrol.y/ll_height            s_consize.s_conw[v_li]=dragcontrol.width/ll_width            s_consize.s_conh[v_li]=dragcontrol.height/ll_height            v_li=v_li+1     Case Line!            line_contr=v_winobj            s_consize.s_conx[v_li]=line_contr.beginx/ll_width         s_consize.s_cony[v_li]=line_contr.beginy/ll_height            s_consize.s_conw[v_li]=line_contr.endx/ll_width            s_consize.s_conh[v_li]=line_contr.endy/ll_height            v_li=v_li+1     Case Oval!            oval_contr=v_winobj            s_consize.s_conx[v_li]=oval_contr.x/ll_width            s_consize.s_cony[v_li]=oval_contr.y/ll_height            s_consize.s_conw[v_li]=oval_contr.width/ll_width            s_consize.s_conh[v_li]=oval_contr.height/ll_height            v_li=v_li+1     Case Rectangle!            rect_contr=v_winobj            s_consize.s_conx[v_li]=rect_contr.x/ll_width            s_consize.s_cony[v_li]=rect_contr.y/ll_height            s_consize.s_conw[v_li]=rect_contr.width/ll_width            s_consize.s_conh[v_li]=rect_contr.height/ll_height            v_li=v_li+1     Case RoundRectangle!            roun_contr=v_winobj            s_consize.s_conx[v_li]=roun_contr.x/ll_width            s_consize.s_cony[v_li]=roun_contr.y/ll_height            s_consize.s_conw[v_li]=roun_contr.width/ll_width            s_consize.s_conh[v_li]=roun_contr.height/ll_height            v_li=v_li+1     Case tab!            l_tab=v_winobj            s_consize.s_conx[v_li]=l_tab.x/ll_width            s_consize.s_cony[v_li]=l_tab.y/ll_height            s_consize.s_conw[v_li]=l_tab.width/ll_width            s_consize.s_conh[v_li]=l_tab.height/ll_height            v_li=v_li+1                        integer li_ti1,li_ti2            for li_ti1=1 to upperbound(l_tab.control[])                for li_ti2=1 to upperbound(l_tab.control[li_ti1].control[])                    uf_position(l_tab.control[li_ti1].control[li_ti2],ll_width,ll_height)                next            next                 Case userobject!            luo_control=v_winobj            s_consize.s_conx[v_li]=luo_control.x/ll_width            s_consize.s_cony[v_li]=luo_control.y/ll_height            s_consize.s_conw[v_li]=luo_control.width/ll_width            s_consize.s_conh[v_li]=luo_control.height/ll_height            v_li=v_li+1                        integer li_uconnum,li_ui            li_uconnum=upperbound(luo_control.control[])            for li_ui=1 to li_uconnum                uf_position(luo_control.control[li_ui],ll_width,ll_height)            nextEnd ChooseReturn 0end functionpublic function integer uf_resize (windowobject v_winobj, long ll_width, long ll_height);DragObject dragcontrolline line_contrOval oval_contrRectangle rect_contrRoundRectangle roun_contrtab l_tabuserobject luo_control    choose case v_winobj.typeof()        case commandbutton!,picturebutton!,checkbox!,radiobutton!, &             statictext!,staticHyperLink!,picture!, &              pictureHyperLink!,groupbox!,singlelineedit!,editmask!, &              multilineedit!,richtextedit!,hscrollbar!,Vscrollbar!, &              Htrackbar!,VtrackBar!,HprogressBar!,VprogressBar!, &              dropdownlistbox!,dropdownpicturelistbox!,listbox!, &              picturelistbox!,listview!,treeview!,datawindow!, &              graph!,olecontrol!            dragcontrol=v_winobj            dragcontrol.move(s_consize.s_conx[v_lj]*ll_width,s_consize.s_cony[v_lj]*ll_height)            dragcontrol.resize(s_consize.s_conw[v_lj]*ll_width,s_consize.s_conh[v_lj]*ll_height)            v_lj=v_lj+1                   case Line!            line_contr=v_winobj            line_contr.beginx=s_consize.s_conx[v_lj]*ll_width            line_contr.beginy=s_consize.s_cony[v_lj]*ll_height            line_contr.endx=s_consize.s_conw[v_lj]*ll_width            line_contr.endy=s_consize.s_conh[v_lj]*ll_height            v_lj=v_lj+1        case Oval!            oval_contr=v_winobj            oval_contr.x=s_consize.s_conx[v_lj]*ll_width            oval_contr.y=s_consize.s_cony[v_lj]*ll_height            oval_contr.width=s_consize.s_conw[v_lj]*ll_width            oval_contr.height=s_consize.s_conh[v_lj]*ll_height            v_lj=v_lj+1        case Rectangle!            rect_contr=v_winobj            rect_contr.x=s_consize.s_conx[v_lj]*ll_width            rect_contr.y=s_consize.s_cony[v_lj]*ll_height            rect_contr.width=s_consize.s_conw[v_lj]*ll_width            rect_contr.height=s_consize.s_conh[v_lj]*ll_height            v_lj=v_lj+1        case RoundRectangle!            roun_contr=v_winobj            roun_contr.x=s_consize.s_conx[v_lj]*ll_width            roun_contr.y=s_consize.s_cony[v_lj]*ll_height            roun_contr.width=s_consize.s_conw[v_lj]*ll_width            roun_contr.height=s_consize.s_conh[v_lj]*ll_height            v_lj=v_lj+1        case tab!            l_tab=v_winobj            l_tab.x=s_consize.s_conx[v_lj]*ll_width            l_tab.y=s_consize.s_cony[v_lj]*ll_height            l_tab.width=s_consize.s_conw[v_lj]*ll_width            l_tab.height=s_consize.s_conh[v_lj]*ll_height            v_lj=v_lj+1                        integer li_ti1,li_ti2            for li_ti1=1 to upperbound(l_tab.control[])                for li_ti2=1 to upperbound(l_tab.control[li_ti1].control[])                    uf_resize(l_tab.control[li_ti1].control[li_ti2],ll_width,ll_height)                next            next                    case userobject!            luo_control=v_winobj            luo_control.x=s_consize.s_conx[v_lj]*ll_width            luo_control.y=s_consize.s_cony[v_lj]*ll_height            luo_control.width=s_consize.s_conw[v_lj]*ll_width            luo_control.height=s_consize.s_conh[v_lj]*ll_height            v_lj=v_lj+1                        integer li_uconnum,li_ui            li_uconnum=upperbound(luo_control.control[])            for li_ui=1 to li_uconnum                uf_resize(luo_control.control[li_ui],ll_width,ll_height)            next                end choosereturn 0end functionevent resize;integer li_ithis.Setredraw(false)for li_i=1 to upperbound(this.control[])    uf_resize(this.control[li_i],newwidth,newheight)nextv_lj=1this.Setredraw(true)end eventon w_autosize.createend onon w_autosize.destroyend onevent open;long ll_width,ll_heightinteger li_ill_width=this.workspacewidth()ll_height=this.workspaceheight()for li_i=1 to upperbound(this.control[])    uf_position(this.control[li_i],ll_width,ll_height)nextend event
  相关解决方案