自適應屏幕分辨率的基類窗口

自適應屏幕分辨率的基類窗口

(加入日期:2001-8-10)

保存文章至硬盤】【打印文章】【字體:

分享到: 0
做一個自適應屏幕分辨率的窗口,當成一個應用程序中所有窗體的基類。這樣整個程序可以很好的適應屏幕分辨率的改變。實現的原理很簡單,就是在窗口打開的時候去RESIZE窗口和窗口中的控件大小,位置。參看下面的源代碼,可以很容易的看懂。

1。新建一個窗口。

爲窗口寫一個函數f_resize()大部分工作就在這裏。
無輸入參數
返回值爲整形:

environment env
integer ii_ScreenWidth,ii_ScreenHeight
double WRadio,HRadio,Radio
integer 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)
if Radio=1.0 then //if the screen is default 800*600
return 0
end if
this.hide()
this.width=(this.width - ii_WinBolderWidth)*Radio + ii_WinBolderWidth
this.height=(this.height - ii_WinBolderHeight)*Radio + ii_WinBolderHeight
integer i
dragobject temp//用於取各種控件

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 case typeof(temp)
  case tab!
   tab mtab
   mtab=temp
   mtab.textsize =  mtab.textsize*Radio//設置字體
  case commandbutton!
   commandbutton cb
   cb = temp
   cb.textsize =  cb.textsize*Radio

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

  case datawindow! // datawindows get zoomed
   datawindow dw
   dw = temp
   dw.Object.DataWindow.zoom = string(int(Radio*100))//注意DATAWINDOW與其它控件的不同

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

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

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

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

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

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

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

end choose
next
this.show()
return 0

函數寫好以後,在窗體的OPEN事件裏調用該函數即可.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章