似乎單用鼠標滾動也可以,不用那個滾動條,我試試看。
授人以渔,不授人以鱼。
CLEAR ALL CLEAR Main() CLEAR ALL RETURN PROCEDURE Main() LOCAL loMainForm loMainForm = CREATEOBJECT("_MainForm") WITH loMainForm .Caption = "可滾動容器示例程序" .MinWidth = 800 .MinHeight = 600 .MaxWidth = 2000 .MaxHeight = 1500 .AutoCenter = .T. .Show ENDWITH READ EVENTS ENDPROC *----------------------------- * 定義主窗體 *----------------------------- DEFINE CLASS _MainForm AS Form ADD OBJECT Container1 AS _Container PROCEDURE Arrange WITH ThisForm.Container1 .Top = 5 .Left = 5 .Height = ThisForm.Height - .Top - 5 .Width = ThisForm.Width - .Left - 5 ENDWITH ENDPROC PROCEDURE Activate ThisForm.Arrange ENDPROC PROCEDURE Resize ThisForm.Arrange ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC ENDDEFINE *----------------------------- * 從可滾動容器基類繼承的子類,添加實際控件,響應事件和方法在基類中 *----------------------------- DEFINE CLASS _Container AS ContainerWithScroll ADD OBJECT Label1 AS Label WITH Caption = "請用鼠標向下滾動:", Height = 25, Width = 150, Top = 10, Left = 50, Alignment = 1 ADD OBJECT Text1 AS TextBox WITH Height = 25, Width = 200, Top = 10, Left = 200 ADD OBJECT Label2 AS Label WITH Caption = "請用鼠標向上滾動:", Height = 25, Width = 150, Top = 800, Left = 50, Alignment = 1 ADD OBJECT Text2 AS TextBox WITH Height = 25, Width = 200, Top = 800, Left = 200 ENDDEFINE *----------------------------- * 可滾動容器基類 *----------------------------- DEFINE CLASS ContainerWithScroll AS Container PROCEDURE Init LOCAL lnIndex WITH This FOR lnIndex = 1 TO .ControlCount WITH .Controls(lnIndex) .AddProperty("Origin_Top", .Top) ENDWITH NEXT ENDWITH ENDPROC PROTECTED PROCEDURE MouseWheel(tnDirection, tnShift, tnXCoord, tnYCoord) LOCAL lnIndex WITH This FOR lnIndex = 1 TO .ControlCount WITH .Controls(lnIndex) .Top = .Top + tnDirection IF .Top > .Origin_Top .Top = .Origin_Top ENDIF ENDWITH NEXT ENDWITH ENDPROC ENDDEFINE