程序代码:
** Test.prg
CREATE CURSOR tt (rb I, cc I, ss C(254))
of = CREATEOBJECT("form1")
of.show(1)
DEFINE CLASS form1 as Form
ADD OBJECT label1 as label WITH top=10,left=10,autosize=.T.,;
caption="随机数范围 运行次数 系数"
ADD OBJECT text1 as textbox WITH top=6,left=72,width=40,value=50
ADD OBJECT text2 as textbox WITH top=6,left=174,width=40,value=200
ADD OBJECT text3 as textbox WITH top=6,left=252,width=40,value=20
ADD OBJECT cmd1 as commandbutton WITH top=6,left=310,width=50,height=22,caption="开始"
ADD OBJECT grid1 as grid1 WITH top=32,left=0,width=this.width,height=this.height-32
PROCEDURE cmd1.click
LOCAL i, x, nRB
SELECT tt
ZAP
FOR i = 1 TO thisform.text2.value
x = INT((thisform.text1.value - 1) * RAND() + 1)
nRB = IIF(x >= thisform.text3.value, 0xFF0000, 0x0000FF)
IF tt.rb != nRB
APPEND BLANK IN "tt"
ENDIF
REPLACE rb WITH nRB, cc WITH cc+1, ss WITH ss-(TRANSFORM(x)+",") IN "tt"
ENDFOR
GO TOP IN "tt"
thisform.grid1.setfocus
ENDPROC
ENDDEFINE
DEFINE CLASS Grid1 as Grid
Visible = .T.
anchor = 15
GridLines = 0
headerheight = 0
AllowCellSelection = .F.
DeleteMark = .F.
RecordMark = .F.
SplitBar = .F.
ScrollBars = 2
HighlightBackColor = 0xFFFFFF
HighlightForeColor=0
columncount = 2
PROCEDURE init
this.column1.width = 50
this.column1.ControlSource = "tt.cc"
this.column2.ControlSource = ""
this.column2.sparse = .F.
this.column2.removeobject("Text1")
this.column2.addobject("cb1", "ColorBar")
this.resize
ENDPROC
PROCEDURE resize
this.column2.width = this.width - this.column1.width
ENDPROC
ENDDEFINE
DEFINE CLASS ColorBar as Container
Visible = .T.
backstyle = 0
borderwidth = 0
ADD OBJECT label1 as label WITH forecolor=0xCCCCCC
PROCEDURE BackStyle_ACCESS
this.label1.width = tt.cc * 20
this.label1.backcolor = tt.rb
this.label1.caption = tt.ss
RETURN this.BackStyle
ENDPROC
ENDDEFINE