Delphi TrackBar On Stop

天涯浪子 提交于 2020-01-06 10:56:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!