我想让listbox的滚动条,
在我选中列表中最中间的记录的时候,每向下移动时滚动就开始向下滚动,
而不是在选中列表显示的最后一条记录时,向下移动时滚动条才向下滚动

解决方案 »

  1.   

    procedure Tlistbox.ListBoxMouseMove(Sender: TObject;
      Shift: TShiftState; X, Y: integer);
    begin
      FNListbox.ItemIndex := FNListbox.ItemAtPos(Point(X, Y), true)
    end;
      

  2.   

    //当鼠标点的时候,实现的,你可以再其他地方,比如按↓的时候,处理该方法,
    procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      SetScrollPos(Listbox1.Handle,SB_VERT,listBox1.ItemIndex,True);
    end;
      

  3.   

    楼上的方法我也试过,不行的;
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      if listbox1.ItemIndex<listbox1.Count-1 then
        listbox1.Selected[listbox1.ItemIndex+1]:= true else listbox1.Selected[0];
        SetScrollPos(Listbox1.Handle,SB_VERT,listBox1.ItemIndex,True);
    end;
      

  4.   

    那你到底先滚动到哪里啊?我给你的那个是跟随你选择的item滚动的,如果你嫌滚动不够,可以
    SetScrollPos(Listbox1.Handle,SB_VERT,listBox1.ItemIndex,True);//修改listBox1.ItemIndex这个参数,比如,listBox1.ItemIndex+3,就是滚动到他的后三个,不过你要控制是否到了最后,
    该能明白点了吧
      

  5.   

    我明天楼主的意思,是让滚动条滚动时listbox的焦点一直在中间,不过想不出如何解决……
      

  6.   

    比如:
    SetScrollPos(Listbox1.Handle,SB_VERT,listBox1.Count,True);
    它是滚动到我列表显示区域的最后,
    而不是我列表中最后的一条记录。
      

  7.   

    哈哈,还是[ hellolongbin(一个人)]了解我 
    :)
      

  8.   

    已经解决了
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      MyRect: TRect;
      Mypos: TPoint;
      y1: Integer;
    begin
      Timer1.Enabled := False;
      if ListBox1.ItemIndex < ListBox1.Count - 1 then
        ListBox1.ItemIndex := ListBox1.ItemIndex + 1
        else ListBox1.ItemIndex := 0;  MyRect := ListBox1.ItemRect(ListBox1.ItemIndex);
      Mypos := MyRect.TopLeft;
      y1 := ListBox1.Height div 2;  if MyPos.Y >= y1 then
        postMessage(ListBox1.Handle,WM_VSCROLL,SB_LINEDOWN,0);
      Timer1.Enabled := True;
    end;