【介紹如何用代碼編寫表單】百錢買百雞
以下代碼,顯示如何創建一個表單,以及在用戶調整窗體尺寸時,内部控件如何隨之變化,拖拉窗口邊框或點擊右上角最大化、恢復按鈕,即可看到效果。
程序代码:
&&百钱买百鸡.prg
CLEAR ALL
oForm = CREATEOBJECT("C_fm1")
WITH oForm
.Caption = "百钱买百鸡(举解法)"
.AutoCenter = .T.
.Show
ENDWITH
READ EVENTS
CLEAR ALL
RETURN
DEFINE CLASS C_fm1 AS Form
ADD OBJECT cmdExit AS CommandButton WITH Caption = "退出", Height = 25, Width = 85
ADD OBJECT pgfContent AS PageFrame WITH PageCount = 2
PROCEDURE Arrange
WITH This.cmdExit
.Top = ThisForm.Height - .Height - 5
.Left = ThisForm.Width - .Width - 6
ENDWITH
WITH This.pgfContent
.Top = 5
.Left = 5
.Height = This.cmdExit.Top - 5
.Width = This.Width - .Left - 5
ENDWITH
ENDPROC
PROCEDURE Activate
This.Arrange
ENDPROC
PROCEDURE Resize
This.Arrange
ENDPROC
PROCEDURE Destroy
CLEAR EVENTS
ENDPROC
PROCEDURE pgfContent.Init
WITH This.Pages(1)
.Caption = "问题描述"
ENDWITH
WITH This.Pages(2)
.Caption = "解答"
ENDWITH
ENDPROC
PROCEDURE cmdExit.Click
RELEASE ThisForm
ENDPROC
ENDDEFINE
*!* &&_screen.Visible= .F.
*!* formHeight=280
*!* formWidth=375
*!* objForm=CREATEOBJECT("fm1")
*!* objForm.show
*!* READ EVENTS
*!* DEFINE CLASS fm1 as Form
*!* windowType=1
*!* showWindow=2
*!* Desktop=.t.
*!* autoCenter=.t.
*!* caption="百钱买百鸡(举解法)"
*!* height=formHeight
*!* width=formWidth
*!* minHeight=280
*!* minWidth=375
*!*
*!* ADD OBJECT cmdExit as myCmd1 WITH top=formHeight-5-25,left=formWidth-5-85
*!*
*!* ADD OBJECT pageFrame1 as myPf WITH top=5,left=5
*!*
*!* PROCEDURE UnLoad
*!* CLEAR EVENTS
*!* ENDPROC
*!*
*!* *!* PROCEDURE resize
*!* *!* &&
*!* *!* ENDPROC
*!* ENDDEFINE
*!* DEFINE CLASS myPf as PageFrame
*!* visible=.t.
*!* &&pageCount=2
*!* height=formHeight-10-25
*!* width=formWidth-5
*!* anchor=15
*!*
*!* ADD OBJECT page1 as myPage1
*!* ADD OBJECT page2 as myPage2
*!*
*!* ENDDEFINE
*!* DEFINE CLASS myPage1 as Page
*!* visible=.t.
*!* caption="问题描述"
*!*
*!* ADD OBJECT p1Lbl1 as qdLbl WITH top=15,left=10,caption="百钱买百鸡,"+CHR(13)+"公鸡、母鸡、小鸡都要买,各能几只?"
*!* ADD OBJECT p1Lbl2 as qdLbl WITH top=45,left=10,caption="铜钱一百"
*!* ADD OBJECT p1Lbl3 as qdLbl WITH top=75,left=10,caption="公鸡一只五钱"
*!* ADD OBJECT p1Lbl4 as qdLbl WITH top=105,left=10,caption="母鸡一只三钱"
*!* ADD OBJECT p1Lbl5 as qdLbl WITH top=135,left=10,caption="小鸡三只一钱"
*!*
*!* ENDDEFINE
*!* DEFINE CLASS qdLbl as Label
*!* fontsize=10
*!* autoSize=.t.
*!* ENDDEFINE
*!* DEFINE CLASS myPage2 as Page
*!* visible=.t.
*!* caption="解答"
*!*
*!* ADD OBJECT p2Edit as qaEdit WITH top=5,left=5,anchor=15
*!* ENDDEFINE
*!* DEFINE CLASS qaEdit as EditBox
*!* visible=.t.
*!* readOnly=.t.
*!*
*!* myHeight=thisform.myPf.height/4 &&??这里怎么算?
*!* Width=thisform.pageFrame1.width-10
*!* text="解答说明"
*!*
*!* ENDDEFINE
*!* DEFINE CLASS myCmd1 as CommandButton
*!* visible=.t.
*!* caption="退出"
*!* height=25
*!* width=85
*!* anchor=12
*!*
*!* PROCEDURE click
*!* thisform.release
*!* ENDPROC
*!* ENDDEFINE
*!*
[此贴子已经被作者于2015-11-20 19:58编辑过]









