虚基类:自适应屏幕分辨率的基类窗口

个自适应屏幕分辨率窗口当成个应用中所有窗体基类这样整个可以很好适应屏幕分辨率改变实现原理很简单就是在窗口打开时候去RESIZE窗口和窗口中Control控件大小位置参看下面源代码可以很容易看懂

1新建个窗口

为窗口写f_resize()大部分工作就在这里
无输入参数
返回值为整形:

environment env
eger ii_ScreenWidth,ii_ScreenHeight
double WRadio,HRadio,Radio
eger ii_WinBolderWidth,ii_WinBolderHeight
getenvironment(env)
ii_WinBolderWidth=this.width - this.WorkSpaceWidth//取得窗体边框宽度
ii_WinBolderHeight=this.height - this.WorkSpaceHeight
ii_ScreenWidth=env.screenwidth
ii_ScreenHeight=env.screenheight
//compute the radio that need be resize

WRadio=ii_ScreenWidth/800 //标准认为屏幕分辨率为800*600
HRadio=ii_ScreenHeight/600//计算出屏幕相对800*600分辨率变化量
Radio=Min(WRadio,HRadio)
Radio=1.0 then // the screen is default 800*600
0
end
this.hide
this.width=(this.width - ii_WinBolderWidth)*Radio + ii_WinBolderWidth
this.height=(this.height - ii_WinBolderHeight)*Radio + ii_WinBolderHeight
eger i
dragobject temp//用于取各种Control控件

for i=1 to upperbound(this.control)
temp=this.control[i]//调整大小位置
temp.width=temp.width*Radio
temp.x=temp.x*Radio
temp.y=temp.y*Radio
temp.Height=temp.Height*Radio
choose typeof(temp)
   tab!
   tab mtab
   mtab=temp
   mtab.textsize =  mtab.textsize*Radio//设置字体
   commandbutton!
   commandbutton cb
   cb = temp
   cb.textsize =  cb.textsize*Radio

   singlelineedit!
   singlelineedit sle
   sle = temp
   sle.textsize=sle.textsize*Radio
   editmask!
   editmask em
   em = temp
   em.textsize =  em.textsize*Radio
  
   text!
   text st
   st = temp
   st.textsize = st.textsize*Radio

   datawindow! // datawindows get zoomed
   datawindow dw
   dw = temp
   dw.Object.DataWindow.zoom = ((Radio*100))//注意DATAWINDOW和其它Control控件区别

   picturebutton!
   picturebutton pb
   pb = temp
   pb.textsize =  pb.textsize*Radio

   checkbox!
   checkbox cbx
   cbx = temp
   cbx.textsize =  cbx.textsize*Radio

   dropdownlistbox!
   dropdownlistbox ddlb
   ddlb = temp
   ddlb.textsize =  ddlb.textsize*Radio

   groupbox!
   groupbox gb
   gb = temp
   gb.textsize =  gb.textsize*Radio

   listbox!
   listbox lb
   lb = temp
   lb.textsize  =  lb.textsize*Radio

   multilineedit!
   multilineedit mle
   mle = temp
   mle.textsize = mle.textsize*Radio

   radiobutton!
   radiobutton rb
   rb = temp
   rb.textsize =  rb.textsize*Radio

end choose
next
this.show
0

写好以后在窗体OPEN事件里即可.
Tags:  什么是虚基类 未定义基类 int的基类 虚基类

延伸阅读

最新评论

发表评论