我都不知道你到底想怎麽用
授人以渔,不授人以鱼。
CLEAR ALL CLEAR IF Application.StartMode == 0 SET PATH TO ADDBS(Application.ActiveProject.HomeDir) + "..\MyTools" ADDITIVE SET PATH TO ADDBS(Application.ActiveProject.HomeDir) + "Source" ADDITIVE ENDIF SET PROCEDURE TO "MyForm" ADDITIVE SET PROCEDURE TO "MyGet" ADDITIVE SET PROCEDURE TO "Ball" ADDITIVE Main() CLEAR ALL RETURN PROCEDURE Main() LOCAL loMainForm loMainForm = CREATEOBJECT("_MainForm") WITH loMainForm .Caption = "Sample" .MinWidth = 800 .MinHeight = 600 .AutoCenter = .T. .Show ENDWITH READ EVENTS ENDPROC FUNCTION Get_Ball(tnMin, tnMax) RETURN INT((tnMax - tnMin + 1) * RAND() + tnMin) ENDFUNC DEFINE CLASS _Input AS MyGet ADD OBJECT Label1 AS Label WITH Caption = "隨機數範圍:" ADD OBJECT Text1 AS TextBox WITH Value = 50 ADD OBJECT Label2 AS Label WITH Caption = "運行次數:" ADD OBJECT Text2 AS TextBox WITH Value = 200 ADD OBJECT Label3 AS Label WITH Caption = "係數:" ADD OBJECT Text3 AS TextBox WITH Value = 25 PROCEDURE Init WITH This .SetAll("Width", 100, "Label") .SetAll("Width", 60, "TextBox") .SetAll("Height", 25) .SetAll("Alignment", 1, "Label") .SetAll("SelectOnEntry", .T., "TextBox") ENDWITH ENDPROC ENDDEFINE DEFINE CLASS _MainForm AS MyForm PROCEDURE Generate_Balls(tnRange, tnTimes, tnCoefficient) LOCAL lnIndex, lcName WITH This.oMap .AddProperty("Balls[" + TRANSFORM(tnTimes) + "]") FOR lnIndex = 1 TO tnTimes lcName = "Balls[" + TRANSFORM(lnIndex) + "]" .AddObject("&lcName", "Ball", Get_Ball(1, tnRange), tnCoefficient) NEXT .SetAll("Visible", .T., "Ball") .Arrange ENDWITH ENDPROC ADD OBJECT oInput AS _Input WITH Top = 5, Left = 5 ADD OBJECT oMap AS Container WITH BorderWidth = 0 PROCEDURE oMap.Arrange LOCAL lnIndex, lnRow, lnCol lnRow = 0 lnCol = 0 FOR lnIndex = 1 TO ALEN(This.Balls, 1) IF (lnIndex > 1) .AND. (This.Balls[lnIndex].ForeColor != This.Balls[lnIndex-1].ForeColor) lnRow = 0 lnCol = lnCol + 1 ENDIF WITH This.Balls[lnIndex] .Top = 5 + lnRow * (.Height + 5) .Left = 5 + lnCol * (.Width + 5) ENDWITH lnRow = lnRow + 1 NEXT ENDPROC PROCEDURE oMap.Clear WITH This DO WHILE .ControlCount > 0 .RemoveObject(.Controls[.ControlCount].Name) ENDDO ENDWITH ENDPROC ADD OBJECT Button AS CommandButton WITH Caption = "開始", Width = 80, Height = 25 PROCEDURE Button.Click WITH This.Parent .oMap.Clear .Generate_Balls(.oInput.Text1.Value, .oInput.Text2.Value, .oInput.Text3.Value) ENDWITH ENDPROC PROCEDURE Arrange DODEFAULT() WITH This.Button .Top = This.oInput.Top .Left = This.Width - .Width - 5 ENDWITH WITH This.oMap .Top = This.oInput.Top + This.oInput.Height + 5 .Left = 5 .Height = This.Height - .Top - 5 .Width = This.Width - .Left - 5 ENDWITH ENDPROC ENDDEFINE
[此贴子已经被作者于2016-1-10 15:44编辑过]
#include "FoxPro.h" DEFINE CLASS Ball AS Label Width = 40 Height = 20 Alignment = 2 BackColor = COLOR_GRAY PROCEDURE Init(tnNumber, tnCoefficient) WITH This .Caption = TRANSFORM(tnNumber) .ForeColor = IIF(tnNumber <= tnCoefficient, COLOR_RED, COLOR_BLUE) ENDWITH ENDPROC ENDDEFINE