![]() |
[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:
|
Re: [TListBox] Aktuelle Scrollzeile
Ja genau das meinte ich, das ist was die procedure ausgerechnet hat.
|
Re: [TListBox] Aktuelle Scrollzeile
Deine neue Prozedur zum Runterscrollen macht jetzt alles perfekt. :) Jetzt ist halt noch die Frage, was man wegen dem Hochscrollen tun könnte.
|
Re: [TListBox] Aktuelle Scrollzeile
Stell doch mal deine neue Demo zum Download bereit, will mal sehen wie es jetzt aussieht.
|
Re: [TListBox] Aktuelle Scrollzeile
Liste der Anhänge anzeigen (Anzahl: 1)
Hier ist sie:
|
Re: [TListBox] Aktuelle Scrollzeile
Liste der Anhänge anzeigen (Anzahl: 1)
Du benutzt für das Hoch- und Runterscrollen anscheinend 2 verschiedene Proceduren. Wenn man bei dir erst runterscrollt, und dann wieder hochscrollt, dann macht deine Trackbar einen großen Sprung.
Hast du schon einmal versucht, für das Hoch- und Runterscrollen, die gleiche Procedur zu nehmen? Ich habe noch ein primitives Beispiel geschrieben, da ich nicht deine Listbox habe, musste ich mich mit einem Timer behelfen. Der Timer soll die Scrollmessage ersetzen. Die Trackbar hatte jedenfalls beim scrollen immer die richtige Position. |
Re: [TListBox] Aktuelle Scrollzeile
:oops:
Ich hatte noch zwei If-Abfragen und noch einen etwas anderen Code:
Delphi-Quellcode:
Danke, jetzt funktioniert alles!
if ScrollCode = scLineDown then
begin ZeroMemory(@WinInfo, sizeOf(WinInfo)); WinInfo.cbSize := SizeOf(WinInfo); GetWindowInfo(lbList.Handle, WinInfo); iHeight := WinInfo.rcClient.Bottom - WinInfo.rcClient.Top; xiScrollV.Max := (lbList.Count * lbList.ItemHeight - iHeight) div lbList.ItemHeight + 1; Rect := lbList.ItemRect(0); xiScrollV.Position := (Rect.Top div lbList.ItemHeight* -1) end else if if ScrollCode = scLineUp then begin ZeroMemory(@WinInfo, sizeOf(WinInfo)); WinInfo.cbSize := SizeOf(WinInfo); GetWindowInfo(lbList.Handle, WinInfo); iHeight:= WinInfo.rcClient.Top - WinInfo.rcClient.Bottom; xiScrollV.Max := (lbList.Count * lbList.ItemHeight - iHeight) div lbList.ItemHeight + 1; Rect := lbList.ItemRect(0) ; xiScrollV.Position := (Rect.Bottom div lbList.ItemHeight * -1); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:37 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