如果每次都刷掉原有的数据,重新输入新的,还好办,要保留原先的数据,过于复杂,还是划不来。
授人以渔,不授人以鱼。
SET DEFAULT TO "Z:\Test\VFP" SET PATH TO "Z:\my_Tools" SET PROCEDURE TO myForm, myCurrencyTextBox CLEAR ALL Main() CLEAR ALL RETURN PROCEDURE Main() LOCAL loForm loForm = NEWOBJECT("_Form") loForm.Show READ EVENTS ENDPROC DEFINE CLASS _Form AS myForm Caption = "Test" ADD OBJECT TextBox1 AS myCurrencyTextBox WITH InputMask = "999999.99", Value = 100.00 PROCEDURE Arrange WITH This.TextBox1 .Top = 5 .Left = 5 ENDWITH ENDPROC ENDDEFINE
#DEFINE LABEL_WIDTH 16 #DEFINE LABEL_HEIGHT 16 DEFINE CLASS myCurrencyTextBox AS Container BorderWidth = 0 Height = 20 InputMask = "9.99" Value = 0 ADD OBJECT PROTECTED TextBox1 AS TextBox WITH Height = 25, SelectOnEntry = .T., Visible = .F. PROCEDURE TextBox1.Init This.AddProperty("Confirm_Value", SET("Confirm")) SET CONFIRM ON ENDPROC PROCEDURE TextBox1.Destroy LOCAL lcConfirm lcConfirm = This.Confirm_Value SET CONFIRM &lcConfirm ENDPROC PROCEDURE TextBox1.Refresh This.Value = This.Parent.Value ENDPROC PROCEDURE TextBox1.Valid WITH This.Parent .Value = This.Value .Refresh ENDWITH This.Visible = .F. ENDPROC PROCEDURE TextBox1.Visible_Assign(tAssign) WITH This .Visible = tAssign .Parent.Height = IIF(!.Visible, LABEL_HEIGHT, LABEL_HEIGHT + .Height) IF .Visible .Refresh .SetFocus ENDIF ENDWITH ENDPROC PROCEDURE Init LOCAL lnIndex WITH This IF !EMPTY(.InputMask) .AddProperty("Labels[" + TRANSFORM(LEN(.InputMask)) + "]") FOR lnIndex = 1 TO ALEN(.Labels, 1) .AddObject(".Labels[" + TRANSFORM(lnIndex) + "]", "Label") WITH .Labels[lnIndex] .BorderStyle = 1 .Width = LABEL_WIDTH .Height = LABEL_HEIGHT .Alignment = 2 .Visible = .T. ENDWITH BINDEVENT(.Labels[lnIndex], "Click", This, "Click") NEXT ENDIF .Arrange .Refresh ENDWITH ENDPROC PROCEDURE Value_Assign(tAssign) This.Value = tAssign This.TextBox1.Value = This.Value ENDPROC PROCEDURE Click This.TextBox1.Visible = !This.TextBox1.Visible ENDPROC PROCEDURE Refresh LOCAL lcString, lnIndex This.SetAll("Caption", " ", "Label") lcString = TRANSFORM(This.Value, This.InputMask) FOR lnIndex = 1 TO LENC(lcString) This.Labels[lnIndex].Caption = SUBSTRC(lcString, lnIndex, 1) NEXT ENDPROC PROCEDURE Arrange LOCAL lnIndex This.Width = 0 FOR lnIndex = 1 TO ALEN(This.Labels, 1) WITH This.Labels[lnIndex] .Top = 0 .Left = (lnIndex - 1) * .Width ENDWITH This.Width = This.Width + This.Labels[lnIndex].Width NEXT WITH This.TextBox1 .Top = LABEL_HEIGHT .Left = 0 .Width = This.Width ENDWITH This.Height = IIF(!This.TextBox1.Visible, LABEL_HEIGHT, LABEL_HEIGHT + This.TextBox1.Height) ENDPROC ENDDEFINE #UNDEFINE LABEL_WIDTH #UNDEFINE LABEL_HEIGHT