先上图 还没有些事件代码 也没添加菜单 不过我添加了括号 如果以后想写带括号的就照这个模板搞了
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
再上代码。。。
程序代码:
clear all
public ga_Keys[30]
ga_Keys[1] = CREATEOBJECT("Key_t", "MC", "MC")
ga_Keys[7] = CREATEOBJECT("Key_t", "MR", "MR")
ga_Keys[13] = CREATEOBJECT("Key_t", "MS", "MS")
ga_Keys[19] = CREATEOBJECT("Key_t", "M1", "M+")
ga_Keys[25] = CREATEOBJECT("Key_t", "M2", "M-")
ga_Keys[2] = CREATEOBJECT("Key_t", "(", "(")
ga_Keys[3] = CREATEOBJECT("Key_t", ")", ")")
ga_Keys[4] = CREATEOBJECT("Key_t", "BS", "←")
ga_Keys[5] = CREATEOBJECT("Key_t", "C1", "CE")
ga_Keys[6] = CREATEOBJECT("Key_t", "C2", "C")
ga_Keys[8] = CREATEOBJECT("Key_t", "7", "7")
ga_Keys[9] = CREATEOBJECT("Key_t", "8", "8")
ga_Keys[10] = CREATEOBJECT("Key_t", "9", "9")
ga_Keys[11] = CREATEOBJECT("Key_t", "/", "/")
ga_Keys[12] = CREATEOBJECT("Key_t", "sqrt", "√")
ga_Keys[14] = CREATEOBJECT("Key_t", "4", "4")
ga_Keys[15] = CREATEOBJECT("Key_t", "5", "5")
ga_Keys[16] = CREATEOBJECT("Key_t", "6", "6")
ga_Keys[17] = CREATEOBJECT("Key_t", "*", "*")
ga_Keys[18] = CREATEOBJECT("Key_t", "%", "%")
ga_Keys[20] = CREATEOBJECT("Key_t", "1", "1")
ga_Keys[21] = CREATEOBJECT("Key_t", "2", "2")
ga_Keys[22] = CREATEOBJECT("Key_t", "3", "3")
ga_Keys[23] = CREATEOBJECT("Key_t", "-", "-")
ga_Keys[24] = CREATEOBJECT("Key_t", "inverse", "1/x")
ga_Keys[26] = CREATEOBJECT("Key_t", "0", "0")
ga_Keys[27] = CREATEOBJECT("Key_t", "sign", "+/-")
ga_Keys[28] = CREATEOBJECT("Key_t", ".", ".")
ga_Keys[29] = CREATEOBJECT("Key_t", "+", "+")
ga_Keys[30] = 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(Str(mlineno) + "表达式错误:" + 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 = 50
Height = 50
*FontName = "Terminal"
Themes = 0
FontSize = 20
*- 键名属性
Key = ""
Procedure Init(t_Key)
With This
.Key = t_Key
.Caption = .Key.Caption
EndWith
EndProc
EndDefine
define class C_Form as Form
MaxButton = .F.
Caption = " 计算器"
Icon = 'D:\VFP\ico\rr.ico'
AutoCenter = .T.
add object C_display as Container with Width = 350, Height = 50,;
BorderWidth = 2
add object C_btnGroup as Container with Width = ThisForm.C_display.Width, Height = 300,;
BorderWidth = 0
procedure C_display.Init
with This
.SpecialEffect = 1
.AddObject("mem_dpy", "Container") && mem_dpy 的意思是memory_display
.mem_dpy.Top = 5
.mem_dpy.Left = 5
.mem_dpy.Width = 40
.mem_dpy.Height = 40
.mem_dpy.SpecialEffect = 1
.AddObject("epn_dpy", "Label") && epn_dpy 的意思是expression_display
.epn_dpy.Top = .mem_dpy.Top
.epn_dpy.Left = .mem_dpy.Left * 2 + .mem_dpy.Width
.epn_dpy.Width = .Width - .mem_dpy.Width - .mem_dpy.Left * 2
.epn_dpy.Height = .Height/2 - .mem_dpy.Top
*.epn_dpy.BackColor = Rgb(0, 0, 255)
.AddObject("rst_dpy", "Label") && rst_dpy 的意思是result_display
.rst_dpy.Top = .Height/2
.rst_dpy.Left = .epn_dpy.Left
.rst_dpy.Width = .epn_dpy.Width
.rst_dpy.Height = .epn_dpy.Height
*.rst_dpy.BackColor = Rgb(255, 0, 0)
.SetAll("Visible", .T.)
.SetAll("Caption", "0.")
.SetAll("Alignment", 1)
.SetAll("BorderWidth", 2)
.SetAll("FontSize", 14)
endwith
endproc
Procedure C_btnGroup.Init
Local lc_KeyName
Local ln_Space
Local ln_Index, ln_Top, ln_Left
ln_Top = 0
ln_Left = 0
ln_Space = 10
For ln_Index = 1 to Alen(ga_Keys, 0)
lc_KeyName = "Key_" + Padl(ln_Index, 2, '0')
This.AddObject(lc_KeyName, "C_Button", ga_Keys[ln_Index])
With This.&lc_KeyName
If InList(ln_Index, 7, 13, 19, 25)
ln_Top = ln_Top + .Height + ln_Space
ln_Left = 0
EndIf
If InList(ln_Index, 8, 9, 10, 14, 15, 16, 20, 21, 22,;
26, 27, 28, 12, 18, 24)
.ForeColor = Rgb(0, 0, 255)
Else
.ForeColor = Rgb(255, 0, 0)
EndIf
.Top = ln_Top
.Left = ln_Left
.Visible = .T.
.Themes = 0
ln_Left = ln_Left + .Width + ln_Space
EndWith
Next
EndProc
procedure Init
with This
.C_display.Top = 35
.C_display.Left = 10
.C_btnGroup.Top = .C_display.Top + .C_display.Height + 10
.C_btnGroup.Left = .C_display.Left
.Width = .C_display.Width + 20
.Height = .C_btnGroup.Top + .C_btnGroup.Height
endwith
endproc
procedure destroy
clear events
endproc
enddefine
[
本帖最后由 有容就大 于 2012-9-19 20:12 编辑 ]