回复 9楼 seekyou3
用5樓的代碼就可以了,平時顯示是零値爲空白,一旦Text1得到焦點,才會顯示出零。
授人以渔,不授人以鱼。
Form1 = CREATEOBJECT("my_Form") Form1.Show READ EVENTS RETURN DEFINE CLASS my_Form AS Form Caption = "文本框不顯示數値零" Height = 200 Width = 300 AutoCenter = .T. ADD OBJECT PROTECTED Text1 AS TextBox WITH Height = 25, Width = 100, Top = 5, Left = 5 ADD OBJECT PROTECTED Text2 AS TextBox WITH Value = "", Height = 25, Width = 100, Top = 35, Left = 5 ADD OBJECT PROTECTED Command1 AS CommandButton WITH Caption = "確定", Height = 25, Width = 60, Top = 65, Left = 5 PROCEDURE Text1.Init WITH This .Value = "" .InputMask = "9999" .Alignment = 1 ENDWITH ENDPROC PROCEDURE Text1.Valid WITH This .Value = TRANSFORM(VAL(.Value), .InputMask) IF EMPTY(VAL(.Value)) .Value = "" ENDIF ENDWITH ENDPROC PROCEDURE Command1.Click WITH This.Parent.Text1 MESSAGEBOX("Text1.Value = " + TRANSFORM(VAL(.Value), .InputMask), 64, "") ENDWITH ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC ENDDEFINE
Form1 = CREATEOBJECT("my_Form") Form1.Show READ EVENTS RETURN DEFINE CLASS my_Form AS Form Caption = "文本框不顯示數値零" Height = 200 Width = 300 AutoCenter = .T. ADD OBJECT PROTECTED Text1 AS TextBox WITH Height = 25, Width = 100, Top = 5, Left = 5 ADD OBJECT PROTECTED Text2 AS TextBox WITH Value = "", Height = 25, Width = 100, Top = 35, Left = 5 ADD OBJECT PROTECTED Command1 AS CommandButton WITH Caption = "確定", Height = 25, Width = 60, Top = 65, Left = 5 PROCEDURE Text1.Init WITH This .AddProperty("TrueValue", 0) .Value = "" .InputMask = "9999" .Alignment = 1 .SelectOnEntry = .T. ENDWITH ENDPROC PROCEDURE Text1.Valid WITH This .TrueValue = INT(VAL(.Value)) .Value = IIF(EMPTY(.TrueValue), "", TRANSFORM(.TrueValue, .InputMask)) ENDWITH ENDPROC PROCEDURE Command1.Click WITH This.Parent.Text1 * * 使用Text1.TrueValue獲取眞値,顯示的.Value是字符型,.TrueValue才是數値型 * MESSAGEBOX("Text1.Value = " + TRANSFORM(.TrueValue, .InputMask), 64, "") ENDWITH ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC ENDDEFINE