maozet
maozet

Reputation: 96

How do I change the width of a ScrollBar?

I would like to change a TFrame's ScrollingBar width.
I know I could change all ScrollingBars in the system by:

SystemParametersInfo(SPI_SETNONCLIENTMETRICS,....

But how do I do it for a specific WinControl?

Upvotes: 3

Views: 8007

Answers (3)

procedure TForm1.FormCreate(Sender: TObject);
var NCMet: TNonClientMetrics;
begin
     FillChar(NCMet, SizeOf(NCMet), 0);
     NCMet.cbSize:=SizeOf(NCMet);
     // get the current metrics
     SystemParametersInfo(SPI_GETNONCLIENTMETRICS, SizeOf(NCMet), @NCMet, 0);
     // set the new metrics
     NCMet.iScrollWidth:=50;
     SystemParametersInfo(SPI_SETNONCLIENTMETRICS, SizeOf(NCMet), @NCMet, SPIF_SENDCHANGE);
end;

Upvotes: -1

Wim ten Brink
Wim ten Brink

Reputation: 26682

A lot of the code within Delphi depends on the width of scrollbars to be the fixed system setting so you can't alter the width without breaking the control. (Not without rewriting the TControlScrollBar and related controls in the VCL.)

You could, of course, hide the default scrollbars of the control and add your own TScrollbar components next to it.


The standard TScrollBar class is a WinControl itself, where the scrollbar is taking the whole width and height of the control. The TControlScrollBar class is linked to other WinControl to manage the default scrollbars that are assigned to Windowed controls. While the raw API could make it possible to use a more flexible width, you'd always have the problem that the VCL will just assume the default system-defined width for these controls.

This also shows the biggest difference between both scrollbar types: TScrollBar has it's own Windows handle while TControlScrollBar borrows it from the related control.

Upvotes: 1

Nick Dandoulakis
Nick Dandoulakis

Reputation: 43110

You can try something like this:

  your_frame.HorzScrollBar.Size := 50;
  your_frame.HorzScrollBar.ButtonSize := your_frame.HorzScrollBar.Size;

Upvotes: 1

Related Questions