我用的是Win8,它的窗口标题都是居中的。
授人以渔,不授人以鱼。
CLEAR ALL PUBLIC ga_Keys[28] ga_Keys[1] = CREATEOBJECT("Key_t", "MC", "MC") ga_Keys[2] = CREATEOBJECT("Key_t", "MR", "MR") ga_Keys[3] = CREATEOBJECT("Key_t", "MS", "MS") ga_Keys[4] = CREATEOBJECT("Key_t", "M1", "M+") ga_Keys[5] = CREATEOBJECT("Key_t", "M2", "M-") ga_Keys[6] = CREATEOBJECT("Key_t", "BS", "←") ga_Keys[7] = CREATEOBJECT("Key_t", "C1", "CE") ga_Keys[8] = CREATEOBJECT("Key_t", "C2", "C") ga_Keys[9] = CREATEOBJECT("Key_t", "sign", "±") ga_Keys[10] = CREATEOBJECT("Key_t", "sqrt", "√") ga_Keys[11] = CREATEOBJECT("Key_t", "7", "7") ga_Keys[12] = CREATEOBJECT("Key_t", "8", "8") ga_Keys[13] = CREATEOBJECT("Key_t", "9", "9") ga_Keys[14] = CREATEOBJECT("Key_t", "/", "/") ga_Keys[15] = CREATEOBJECT("Key_t", "%", "%") ga_Keys[16] = CREATEOBJECT("Key_t", "4", "4") ga_Keys[17] = CREATEOBJECT("Key_t", "5", "5") ga_Keys[18] = CREATEOBJECT("Key_t", "6", "6") ga_Keys[19] = CREATEOBJECT("Key_t", "*", "*") ga_Keys[20] = CREATEOBJECT("Key_t", "inverse", "1/x") ga_Keys[21] = CREATEOBJECT("Key_t", "1", "1") ga_Keys[22] = CREATEOBJECT("Key_t", "2", "2") ga_Keys[23] = CREATEOBJECT("Key_t", "3", "3") ga_Keys[24] = CREATEOBJECT("Key_t", "-", "-") ga_Keys[25] = CREATEOBJECT("Key_t", "=", "=") ga_Keys[26] = CREATEOBJECT("Key_t", "0", "0") ga_Keys[27] = CREATEOBJECT("Key_t", ".", ".") ga_Keys[28] = CREATEOBJECT("Key_t", "+", "+") PUBLIC gc_Expression, gc_Result gc_Expression = "" gc_Result = "" SET DECIMALS TO 4 ON ERROR DO errHandler WITH ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO( ) Main() ON ERROR CLEAR ALL RETURN PROCEDURE errHandler(merror, mess, mess1, mprog, mlineno) MESSAGEBOX("表达式错误:" + mess) ENDPROC PROCEDURE Main() LOCAL lo_MainForm lo_MainForm = NEWOBJECT("C_FORM") lo_MainForm.Show READ EVENTS ENDPROC DEFINE CLASS Key_t AS Custom ID = "" && 键标识 Caption = "" && 键标签 PROCEDURE Init(tc_ID, tc_Caption) WITH This .ID = tc_ID .Caption = tc_Caption ENDWITH ENDPROC ENDDEFINE DEFINE CLASS C_BUTTON AS CommandButton Width = 40 Height = 32 FontName = "Terminal" *- 键名属性 Key = "" PROCEDURE Init(t_Key) WITH This .Key = t_Key .Caption = .Key.Caption ENDWITH ENDPROC PROCEDURE Click DO CASE CASE ISDIGIT(This.Key.ID) .OR. INLIST(This.Key.ID, "+", "-", "*", "/") gc_Expression = gc_Expression + This.key.Caption CASE This.Key.ID == "BS" gc_Expression = LEFT(gc_Expression, LEN(gc_Expression) - 1) CASE This.Key.ID == "C2" gc_Expression = "" gc_Result = "" CASE This.Key.ID == "=" gc_Result = TRANSFORM(&gc_Expression) CASE This.Key.ID == "sqrt" gc_Result = TRANSFORM(SQRT(&gc_Expression)) ENDCASE ThisForm.Refresh ENDPROC ENDDEFINE DEFINE CLASS C_FORM AS Form Caption = "计算器" MaxButton = .F. BorderStyle = 1 AutoCenter = .T. ADD OBJECT ContentBox AS Container WITH Width = 240, Height = 50 ADD OBJECT ButtonsPanel AS Container WITH Width = 240, Height = 250, BorderWidth = 0 PROCEDURE ContentBox.Init WITH This .SpecialEffect = 1 .AddObject("lbl_Expression", "Label") .lbl_Expression.Top = 2 .AddObject("lbl_Result", "Label") .lbl_Result.Top = 25 .SetAll("Left", 2) .SetAll("Width", 220) .SetAll("Height", 20) .SetAll("FontSize", 12) .SetAll("Alignment", 1) .SetAll("Visible", .T.) ENDWITH ENDPROC PROCEDURE ContentBox.Refresh This.lbl_Expression.Caption = gc_Expression This.lbl_Result.Caption = gc_Result ENDPROC PROCEDURE ButtonsPanel.Init LOCAL lc_KeyName LOCAL la_Padding[5] LOCAL ln_Index, ln_Top, ln_Left la_Padding[1] = 0 la_Padding[2] = 0 la_Padding[3] = 0 la_Padding[4] = 0 la_Padding[5] = 10 ln_Top = la_Padding[1] ln_Left = la_Padding[4] FOR ln_Index = 1 TO ALEN(ga_Keys,1) lc_KeyName = "Key_" + PADL(ln_Index, 2, '0') This.AddObject(lc_KeyName, "C_BUTTON", ga_Keys[ln_Index]) WITH This.&lc_KeyName IF .Key.ID == '0' .Width = 2 * .Width + la_Padding[5] ENDIF IF .Key.ID == '=' .Height = 2 * .Height + la_Padding[5] ENDIF IF INLIST(ln_Index, 6, 11, 16, 21, 26) ln_Top = ln_Top + .Height + la_Padding[5] ln_Left = la_Padding[4] ENDIF .Top = ln_Top .Left = ln_Left .Visible = .T. ln_Left = ln_Left + .Width + la_Padding[5] ENDWITH NEXT ENDPROC PROCEDURE Init WITH This .ContentBox.Top = 5 .ContentBox.Left = 20 .ButtonsPanel.Top = .ContentBox.Top + .ContentBox.Height + 10 .ButtonsPanel.Left = 20 .Width = .ButtonsPanel.Width + 40 .Height = .ButtonsPanel.Top + .ButtonsPanel.Height + 5 ENDWITH ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC ENDDEFINE