Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi [TListBox] Aktuelle Scrollzeile (https://www.delphipraxis.net/86283-%5Btlistbox%5D-aktuelle-scrollzeile.html)

Nils_13 12. Feb 2007 09:33


[TListBox] Aktuelle Scrollzeile
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hi,

wenn man in einer Listbox das Mouserad abfängt, dann möchte ich, dass eine TrackBar die Position erhält, an welcher gerade die ListBox steht. Ich meine NICHT den ItemIndex. Es ist schwer zu erklären, deshalb ist im Anhang ein kleines Beispiel, welches dieses Problem demonstrieren soll: Benutzt einfach den Slider und bewegt ihn ein paar Mal hoch und runter. Ich möchte genau dies mit dem MouseRad ermöglichen. Es ist wirklich nicht über ItemIndex zu lösen, da man beim scrollen nicht den ItemIndex beinflusst und die künstliche ScrollBar somit zum stehen kommt.
Zum Scrollen (reagiert auf Vertikal und Horizontal, nur Vertikal ist nötig) hier den zur Verfügung stehenden Code:
Delphi-Quellcode:
procedure TfrmMain.lbListScroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
  //
end;

bitsetter 12. Feb 2007 10:17

Re: [TListBox] Aktuelle Scrollzeile
 
Ich weis zwar nicht, ab du sowas meinst, aber kannst ja mal versuchen.
Delphi-Quellcode:
var
  Rect: TRect;
begin
  if listbox1.Count> 0 then
  begin
    Rect:= listbox1.ItemRect(0) ;
    caption:= inttostr(Rect.Top div listbox1.ItemHeight* -1);//Beispiel
    Trackbar1.Position:= (Rect.Top div listbox1.ItemHeight* -1)
  end;
end;
Der Code funktioniert nur beim runterscrollen.

Nils_13 13. Feb 2007 16:55

Re: [TListBox] Aktuelle Scrollzeile
 
Thx, das funktioniert perfekt. Wie sieht das dann beim Hochscrollen aus ? Steh gerade echt auf dem Schlauch.

bitsetter 13. Feb 2007 20:07

Re: [TListBox] Aktuelle Scrollzeile
 
Ich hoffe mal, dass dieser Code beim Hochscrollen funktioniert.
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
  var
  Rect: TRect;
  WinInfo: TWindowInfo;
  iHeight: integer;
begin
  Caption:= '0';
  if listbox1.Count> 0 then
  begin
    ZeroMemory(@WinInfo, sizeOf(WinInfo));
    WinInfo.cbSize:= SizeOf(WinInfo);
    GetWindowInfo(listbox1.Handle, WinInfo);
    //iHeight= sichtbare Bereich in der Listbox
    iHeight:= WinInfo.rcClient.Bottom- WinInfo.rcClient.Top;
    Rect:= Listbox1.ItemRect(Listbox1.Count) ;
    if Rect.Bottom> iHeight then
    begin
      caption:= inttostr((Rect.Bottom- iHeight)div listbox1.ItemHeight);//* -1);
      //Trackbar1.Position:= ((Rect.Bottom- iHeight) div listbox1.ItemHeight);
    end;
  end;
end;

Nils_13 13. Feb 2007 20:12

Re: [TListBox] Aktuelle Scrollzeile
 
Leider nicht.
Delphi-Quellcode:
procedure TfrmMain.lbListScroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
var Rect   : TRect;
    WinInfo : TWindowInfo;
    iHeight : integer;
begin
  if ScrollCode = scLineDown then
  begin
    Rect := lbList.ItemRect(0);
    xiScrollV.Position := (Rect.Top div lbList.ItemHeight * -1);
  end else
  if ScrollCode = scLineUp then
  begin
    ZeroMemory(@WinInfo, sizeOf(WinInfo));
    WinInfo.cbSize:= SizeOf(WinInfo);
    GetWindowInfo(lbList.Handle, WinInfo);
    //iHeight= sichtbare Bereich in der Listbox
    iHeight:= WinInfo.rcClient.Bottom- WinInfo.rcClient.Top;

    Rect := lbList.ItemRect(lbList.Count);
    if Rect.Bottom > iHeight then
      xiScrollV.Position := ((Rect.Bottom- iHeight) div lbList.ItemHeight);
  end;
end;
Er scrollt hoch und danach wieder runter.

bitsetter 13. Feb 2007 20:22

Re: [TListBox] Aktuelle Scrollzeile
 
Welchen Wert hat bei dir
Delphi-Quellcode:
Trackbar1.Max
?
Die Procedure erechnet praktisch, wieviel Items nicht mehr sichtbar sind, also unterhalb der Listbox sind.

Nils_13 13. Feb 2007 20:25

Re: [TListBox] Aktuelle Scrollzeile
 
Ah, daran könnte es liegen. Er hat lbList.Count (Playlistcount bzw. Listboxcount). Wie muss man denn hierfür den Max-Wert der Trackbar setzen ?

bitsetter 13. Feb 2007 20:50

Re: [TListBox] Aktuelle Scrollzeile
 
Versuche erst einmal
Delphi-Quellcode:
Trackbar1.Position:= lbList.Count- //Items unterhalb der Listbox(also die nicht mehr sichtbar sind)
Ansonsten so:
Delphi-Quellcode:
var
  Rect: TRect;
  WinInfo: TWindowInfo;
  iHeight: integer;
begin
  if listbox1.Count> 0 then
  begin
    ZeroMemory(@WinInfo, sizeOf(WinInfo));
    WinInfo.cbSize:= SizeOf(WinInfo);
    GetWindowInfo(listbox1.Handle, WinInfo);
    iHeight:= WinInfo.rcClient.Bottom- WinInfo.rcClient.Top;
    Trackbar1.Max:= ((Listbox1.Count* Listbox1.ItemHeight)-  iHeight) div Listbox1.ItemHeight+ 1;
    Rect:= listbox1.ItemRect(0) ;
    caption:= inttostr(Rect.Top div listbox1.ItemHeight* -1);//Beispiel
    Trackbar1.Position:= (Rect.Top div listbox1.ItemHeight* -1)
  end;
end;
Das würde bei dir aber komisch aussehen, da du eine Trackbar aber keine Scrollbar hast.

EDIT: Code nochmal geändert, funktioniert im prinzip aber genauso.

Nils_13 13. Feb 2007 21:14

Re: [TListBox] Aktuelle Scrollzeile
 
Was heißt "Items unterhalb der Listbox" ?

Daniel G 13. Feb 2007 21:20

Re: [TListBox] Aktuelle Scrollzeile
 
Zitat:

Zitat von Nils_13
Was heißt "Items unterhalb der Listbox" ?

Die Items, die ausgeblendet sind, sprich' "Unter'm unterstem Rand der Listbox" :wink:


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:18 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz