问题
I am making a basic music player and am using a TTrackBar as the progress in the song. As well I want to make it so u can drag the bar and fast forward the song.
Currently I have an OnChange event with the following line:
MediaPlayer1.position := TrackBar1.value... (with proper casting)
but what happens is that it skips the song along as I drag making a choppy sound as it plays the song at certain random points along the way.
What I really want is for when the user stops dragging the song should change. What event is this? The onStopDrop even doesn't do the trick..
回答1:
The scroll notification messages arrive though WM_HSCROLL
or WM_VSCROLL
, depending on the orientation of your track bar. These surface in the VCL control as CN_HSCROLL
and CN_VSCROLL
. You need to handle these messages and ignore message for which the scroll code is TB_THUMBTRACK
to prevent the control to fire the OnChange
event when the user drags the slider.
For example, here is an interposer control that does what you need:
type
TTrackBar = class(Vcl.ComCtrls.TTrackBar)
protected
procedure CNHScroll(var Message: TWMHScroll); message CN_HSCROLL;
procedure CNVScroll(var Message: TWMVScroll); message CN_VSCROLL;
end;
implementation
procedure TTrackBar.CNHScroll(var Message: TWMHScroll);
begin
if Message.ScrollCode = TB_THUMBTRACK then
Message.Result := 0
else
inherited;
end;
procedure TTrackBar.CNVScroll(var Message: TWMVScroll);
begin
if Message.ScrollCode = TB_THUMBTRACK then
Message.Result := 0
else
inherited;
end;
来源:https://stackoverflow.com/questions/24073183/delphi-trackbar-on-stop