程序代码:
CLEAR ALL
CLOSE DATABASES ALL
SET DEFAULT TO (Application.ActiveProject.HomeDir)
Form1 = NEWOBJECT("C_Form")
Form1.Show
READ EVENTS
CLOSE DATABASES ALL
CLEAR ALL
RETURN
DEFINE CLASS C_Form AS Form
Caption = "自定义按钮测试"
WindowState = 2
ADD OBJECT Grid1 AS Grid
PROCEDURE Load
USE Table1 IN 0
ENDPROC
PROCEDURE Unload
USE IN Table1
ENDPROC
PROCEDURE Arrange
WITH This.Grid1
.Top = 5
.Left = 5
.Width = ThisForm.Width - .Left - 5
.Height = ThisForm.Height - .Top - 5
ENDWITH
ENDPROC
PROCEDURE Activate
ThisForm.Arrange
ENDPROC
PROCEDURE Resize
ThisForm.Arrange
ENDPROC
PROCEDURE Destroy
CLEAR EVENTS
ENDPROC
PROCEDURE Grid1.Init
WITH This
.RecordSourceType = 1
.RecordSource = "Table1"
WITH .Columns(3)
.RemoveObject("Text1")
.AddObject("Button1", "GridCommandButton")
WITH .Button1
.ControlSource = "Table1.F03"
.TrueCaption = "Yes"
.FalseCaption = "No"
.Width = 60
.Height = 20
.Visible = .T.
ENDWITH
.CurrentControl = "Button1"
.Sparse = .F.
.Width = 60
ENDWITH
.RowHeight = 22
ENDWITH
ENDPROC
ENDDEFINE
DEFINE CLASS GridCommandButton AS Container
BorderWidth = 0
ControlSource = ""
TrueCaption = "是"
FalseCaption = "否"
ADD OBJECT Text1 AS TextBox WITH Visible = .F.
ADD OBJECT Button1 AS CommandButton
PROCEDURE Width_Assign(tAssign)
This.Button1.Width = tAssign
ENDPROC
PROCEDURE Height_Assign(tAssign)
This.Button1.Height = tAssign
ENDPROC
PROCEDURE ControlSource_Assign(tAssign)
This.Text1.ControlSource = tAssign
ENDPROC
PROCEDURE Text1.Value_Assign(tAssign)
This.Value = tAssign
WITH This.Parent.Button1
.Caption = IIF(tAssign, This.Parent.TrueCaption, This.Parent.FalseCaption)
.VisualEffect = IIF(tAssign, 2, 1)
ENDWITH
ENDPROC
PROCEDURE Button1.Click
WITH This.Parent.Text1
.Value = !.Value
ENDWITH
ENDPROC
ENDDEFINE

授人以渔,不授人以鱼。






