Title: Enable and disable the arrows of horizontal or vertical scrollbars.
Question: How to enable and disable the arrows of horizontal or vertical scrollbars.
Answer:
The arrows of horizontal and vertical scrollbars can be individually disabled or enabled by sending the message 'SBM_ENABLEARROWS'.
The wparam ofthe message can have the following values
ESB_DISABLE_BOTH Disables both arrows on a scroll bar.
ESB_DISABLE_DOWN Disables the down arrow on a vertical scroll bar.
ESB_DISABLE_LTUP Disables the left arrow on a horizontal scroll bar or the up arrow on a vertical scroll bar.
ESB_DISABLE_LEFT Disables the left arrow on a horizontal scroll bar.
ESB_DISABLE_RTDN Disables the right arrow on a horizontal scroll bar or the down arrow on a vertical scroll bar.
ESB_DISABLE_UP Disables the up arrow on a vertical scroll bar.
ESB_ENABLE_BOTH Enables both arrows on a scroll bar.
Below is a sample code.
Add a scrollbar and 6 buttons to a form.
unit ScrollBarEnable;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ToolWin, ComCtrls, Buttons, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
ScrollBar1: TScrollBar;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMessage(scrollbar1.handle,SBM_ENABLE_ARROWS,ESB_DISABLE_BOTH,0);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendMessage(scrollbar1.handle,SBM_ENABLE_ARROWS,ESB_ENABLE_BOTH,0);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
SendMessage(scrollbar1.handle,SBM_ENABLE_ARROWS,ESB_ENABLE_BOTH,0);
SendMessage(scrollbar1.handle,SBM_ENABLE_ARROWS,ESB_DISABLE_RIGHT,0);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
SendMessage(scrollbar1.handle,SBM_ENABLE_ARROWS,ESB_DISABLE_LEFT,0);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
SendMessage(scrollbar1.handle,SBM_ENABLE_ARROWS,ESB_ENABLE_BOTH,0);
SendMessage(scrollbar1.handle,SBM_ENABLE_ARROWS,ESB_DISABLE_LEFT,0);
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
SendMessage(scrollbar1.handle,SBM_ENABLE_ARROWS,ESB_DISABLE_RIGHT,0);
end;