text背景变颜色
拟让text大于某数值时背景颜色变红,同时出警告对话框,请指教。
#DEFINE RED RGB(255,0,0) frm_Test = CREATEOBJECT("_Test") frm_Test.Show READ EVENTS RETURN DEFINE CLASS _Test AS Form Caption = "Text背景變顔色" AutoCenter = .T. ADD OBJECT PROTECTED Label1 AS Label WITH Caption = "請輸入數値:", Height = 25, Width = 100, Alignment = 1 ADD OBJECT PROTECTED Text1 AS TextBox WITH Value = 130000, Height = 25, Width = 60 ADD OBJECT PROTECTED Label2 AS Label WITH Caption = "當輸入數値大於等於120000時將會給出警告信息", Height = 50, AutoSize = .T. PROCEDURE Arrange WITH This.Label1 .Top = 5 .Left = 5 ENDWITH WITH This.Text1 .Top = This.Label1.Top .Left = This.Label1.Left + This.Label1.Width ENDWITH WITH This.Label2 .Top = This.Label1.Top + This.Label1.Height + 5 .Left = This.Label1.Left ENDWITH WITH This .MinHeight = .Label2.Top + .Label2.Height + 5 .MinWidth = MAX(.Text1.Left + .Text1.Width, .Label2.Width) + 10 ENDWITH ENDPROC PROCEDURE Activate This.Arrange ENDPROC PROCEDURE Resize This.Arrange ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC PROCEDURE Text1.Refresh This.BackColor = IIF(This.Value >= 120000, RED, ThisForm.BackColor) ENDPROC PROCEDURE Text1.Valid This.Refresh ENDPROC ENDDEFINE
#DEFINE WARNING_VALUE 120000 #DEFINE RED RGB(255,0,0) frm_Test = CREATEOBJECT("_Test") frm_Test.Show READ EVENTS RETURN DEFINE CLASS _Test AS Form Caption = "Text背景變顔色" ShowTips = .T. AutoCenter = .T. ADD OBJECT PROTECTED Label1 AS Label WITH Caption = "請輸入數値:", Height = 25, Width = 100, Alignment = 1 ADD OBJECT PROTECTED Text1 AS TextBox WITH Value = 130000, Height = 25, Width = 60, ToolTipText = "當輸入數値≥" + ALLTRIM(STR(WARNING_VALUE)) + "時將會給出警告信息" PROCEDURE Arrange WITH This.Label1 .Top = 5 .Left = 5 ENDWITH WITH This.Text1 .Top = This.Label1.Top .Left = This.Label1.Left + This.Label1.Width ENDWITH WITH This .MinHeight = .Text1.Top + .Text1.Height + 5 .MinWidth = .Text1.Left + .Text1.Width + 5 ENDWITH ENDPROC PROCEDURE Activate This.Arrange ENDPROC PROCEDURE Resize This.Arrange ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC PROCEDURE Text1.Refresh This.BackColor = IIF(This.Value >= WARNING_VALUE, RED, ThisForm.BackColor) ENDPROC PROCEDURE Text1.Valid This.Refresh ENDPROC ENDDEFINE