unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, CommCtrl, StdCtrls;
// uses : CommCtrl
// TScrollBar um ein OnChanged Ereignis erweitern
type
TScrollBar =
class(ComCtrls.TScrollBar)
private
FOnChanged : TNotifyEvent;
procedure CNHScroll(
var msg: TWMHScroll);
message CN_HSCROLL;
published
property OnChanged: TNotifyEvent
read FOnChanged
write FOnChanged;
property OnMouseDown;
property OnMouseUp;
property OnClick;
public
end;
type
TForm1 =
class(TForm)
Memo1: TMemo;
ListBox1: TListBox;
ScrollBar1: TScrollBar;
procedure FormCreate(Sender: TObject);
private
procedure ScrollBarChanged(Sender: TObject);
procedure ScrollBarMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ScrollBarMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ScrollBarClick(Sender: TObject);
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TScrollBar.CNHScroll(
var msg: TWMHScroll);
begin
inherited;
if Assigned(fOnChanged)
then
if (msg.ScrollCode
in [TB_THUMBPOSITION, TB_LINEUP, TB_LINEDOWN, TB_PAGEUP, TB_PAGEDOWN])
then
begin
FOnChanged(Self);
end;
end;
procedure TForm1.ScrollBarChanged(Sender: TObject);
begin
ListBox1.Items.Add('
Position geändert ! ');
end;
procedure TForm1.ScrollBarMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ListBox1.Items.Add('
ScrollBar OnMouseDown');
end;
procedure TForm1.ScrollBarMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ListBox1.Items.Add('
ScrollBar OnMouseUp');
end;
procedure TForm1.ScrollBarClick(Sender: TObject);
begin
ListBox1.Items.Add('
ScrollBar OnClick');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ScrollBar1.OnChanged := ScrollBarChanged;
ScrollBar1.OnMouseDown := ScrollBarMouseDown;
ScrollBar1.OnMouseUp := ScrollBarMouseUp;
ScrollBar1.OnClick := ScrollBarClick;
end;
end.