如何判断ScrollBar滑块是向上运动还是向下运动???我怎么才能知道,我拖动滑块时是向上拖动的,还是向下拖动的.

解决方案 »

  1.   

    例如:Option Explicit'Powered by Jadeluo, 2005/05/21Dim Old_Value As IntegerPrivate Sub Form_Load()
        VScroll1.Value = (VScroll1.Min + VScroll1.Max) \ 2
        Old_Value = VScroll1.Value
        Label1.Caption = ""
    End SubPrivate Sub VScroll1_Change()
        If Old_Value > VScroll1.Value Then
            Label1.Caption = "向上"
        Else
            Label1.Caption = "向下"
        End If
        Old_Value = VScroll1.Value
    End SubPrivate Sub VScroll1_Scroll()
        VScroll1_Change
    End Sub
      

  2.   

    Delphi的例子:
    unit Unit1;//Powered by Jadeluo, 2005/05/21interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        ScrollBar1: TScrollBar;
        Label1: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
          var ScrollPos: Integer);
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      ScrollBar1.Position := (ScrollBar1.Min + ScrollBar1.Max) div 2;
      Label1.Caption := '';
    end;procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);
    begin
      case ScrollCode of
        scLineUp  : Label1.Caption := 'Up or Left';
        scLineDown : Label1.Caption := 'Down or Right';
        scPageUp  : Label1.Caption := 'PageUp';
        scPageDown : Label1.Caption := 'PageDown';
        scEndScroll: Label1.Caption := 'Finished';
      end;
    end;end.
      

  3.   

    jadeluo(秀峰) 
    谢谢; VB 和DElphi 的例子都看.但是,我想知道的是用鼠标点住滑块拖动时的方向.
    不是按钮和翻页时的方向
      

  4.   

    unit Unit1;//Powered by Jadeluo, 2005/05/21interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        ScrollBar1: TScrollBar;
        Label1: TLabel;
        Label2: TLabel;
        procedure ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
          var ScrollPos: Integer);
      end;var
      Form1: TForm1;implementation{$R *.dfm}var
      OldValue : Integer;procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);
    begin
      case ScrollCode of
        scLineUp  : Label1.Caption := 'Up or Left';
        scLineDown : Label1.Caption := 'Down or Right';
        scPageUp  : Label1.Caption := 'PageUp';
        scPageDown : Label1.Caption := 'PageDown';
        scEndScroll: Label1.Caption := 'Finished';
        scTrack    : begin
          if OldValue < ScrollPos then
            Label2.Caption := 'Moving Down'
          else
            Label2.Caption := 'Moving Up';
          OldValue := ScrollPos;
        end;
      end;
    end;end.
      

  5.   

    十分感谢 jadeluo(秀峰) 兄
    我当时把Oldvale变量放到了ScrollBar1Scroll事件中.
    在OnCheng事件里对比的Oldvale 和ScrollBar1.Postion的值,这样做,慢点拖还行,快了就不行了。
    没想到都放 ScrollBaScroll中就行了。。呵呵再次对帮助过我的朋友们进行感谢。。*^_^*