Delphi TrackBar停止 [英] Delphi TrackBar On Stop
问题描述
我正在制作一个基本的音乐播放器,并使用TTrackBar作为歌曲的进度.我也想制作它,以便您可以拖动该栏并快进歌曲.
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.
当前,我有一个带有以下行的OnChange事件:
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.
我真正想要的是当用户停止拖动歌曲时应该更改的内容.这是什么事onStopDrop甚至无法解决问题.
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..
推荐答案
滚动通知消息通过WM_HSCROLL
或WM_VSCROLL
到达,具体取决于轨迹栏的方向. VCL中的这些表面控制为CN_HSCROLL
和CN_VSCROLL
.您需要处理这些消息,并忽略滚动代码为TB_THUMBTRACK
的消息,以防止控件在用户拖动滑块时触发OnChange
事件.
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;
这篇关于Delphi TrackBar停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!