![]() |
[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; |
Re: [TListBox] Aktuelle Scrollzeile
Ich weis zwar nicht, ab du sowas meinst, aber kannst ja mal versuchen.
Delphi-Quellcode:
Der Code funktioniert nur beim runterscrollen.
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; |
Re: [TListBox] Aktuelle Scrollzeile
Thx, das funktioniert perfekt. Wie sieht das dann beim Hochscrollen aus ? Steh gerade echt auf dem Schlauch.
|
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; |
Re: [TListBox] Aktuelle Scrollzeile
Leider nicht.
Delphi-Quellcode:
Er scrollt hoch und danach wieder runter.
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; |
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. |
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 ?
|
Re: [TListBox] Aktuelle Scrollzeile
Versuche erst einmal
Delphi-Quellcode:
Ansonsten so:
Trackbar1.Position:= lbList.Count- //Items unterhalb der Listbox(also die nicht mehr sichtbar sind)
Delphi-Quellcode:
Das würde bei dir aber komisch aussehen, da du eine Trackbar aber keine Scrollbar hast.
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; EDIT: Code nochmal geändert, funktioniert im prinzip aber genauso. |
Re: [TListBox] Aktuelle Scrollzeile
Was heißt "Items unterhalb der Listbox" ?
|
Re: [TListBox] Aktuelle Scrollzeile
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:12 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz