Link to home
Start Free TrialLog in
Avatar of mullet_attack
mullet_attack

asked on

Change Scrollbar width programmatically

I need to change the width of the scrollbar in a grid component. I know I can do this via "Display Properties > Appearance", but that changes it for all scrollbars.

I need to change the width of just one scrollbar on a grid programatically, as the application may be used on a touch screen, and the default scrollbar size is too small for fingers to click on accurately.

thanx.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

where is the scrollbar->which control?
which delphi version do you use?
Avatar of Cynna
Cynna

mullet_attack,

Scroll bar width is a system property. You could change it programatically, but this change will have system-wide effect.
You have two options:

a) If you insist on this, you might change it temporarily, and then, before your app finishes, restore it to original setting.

b) IMHO, you should rethink your app design: use your own scroll bars and them programatically synchronize them with your grid.
no no, cynna

for a form you can easy adjust the scrollbars by properties

see HorzScrollBar-property and VertScrollBar-property
and adjust there the size

meikl ;-)
Yes, but I don't know any standard delphi
*grid* control that relies on TControlScrollBar.
I assume mullet_attack referenced TStringGrid if he didn't
explicitly stated what grid component he had in mind.

But, anyway, thanks for the TControlScrollBar lesson... :)

Avatar of mullet_attack

ASKER

Any grid derived from TCustomGrid.

Cynna, how do I change the system-wide scrollbar width property programatically. The idea of my app changing it, then changing back on exit will do.
you should never do things like this !!!
change the whole systems properties just because your app looks better that way ? do it and you'll see the horrific response from the users

it'd be really better if you'd use some other grid which has this property changeable
Lee Nover, when I want your opinion I'll ask for it.

What I want / need is an answer to my question, not your comments on what my users will or won't like. Have you EVER tried to used a scrollbar on a touch screen? Obviously not, unless you are using some other small appendage instead of your finger.

Secondly, you would know that ALL grids in Delphi derive from TCustomGrid, which a decendant of TWincontrol, so they ALL use WS_?SCROLL in their CreateWindowEx, and therefore they ALL have the same issue.

Before anyone flames me for my harsh response, let me point out that I phrased my original question quite carefully, and that I thank the other repondants unreservedly.

Now, back to topic, does anyone know how to change the systemwide scrollbar width setting from Delphi please?
ASKER CERTIFIED SOLUTION
Avatar of Lee_Nover
Lee_Nover

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mullet_attack,

Lee Nover gave you correct answer. You just have to
restore it on your App close. I already wrote a demo, so here you go (principle is the same, so if you like it, points go to Lee Nover, of course)


var  
 oldMetrics: NONCLIENTMETRICS; // global storage for original settings

// (....)

function SetScrollbarWidth(NewWidth: Integer): Boolean;
var currentMetrics: NONCLIENTMETRICS;
begin
  oldMetrics.cbSize := SizeOf(oldMetrics);
  if not SystemParametersInfo(SPI_GETNONCLIENTMETRICS, SizeOf(oldMetrics),
                              @oldMetrics, SPIF_SENDCHANGE) then begin
    Result := FALSE;  Exit;
  end;
  currentMetrics:=oldMetrics;
  currentMetrics.iScrollWidth:=NewWidth;
  Result :=SystemParametersInfo(SPI_SETNONCLIENTMETRICS, SizeOf(currentMetrics),
                                @currentMetrics, SPIF_SENDCHANGE);

end;

function RestoreScrollbarWidth: Boolean;
var currentMetrics: NONCLIENTMETRICS;
begin
  Result :=SystemParametersInfo(SPI_SETNONCLIENTMETRICS, SizeOf(oldMetrics),
                                @oldMetrics, SPIF_SENDCHANGE);
end;

// DEMO:
// --------------
procedure TForm1.Button1Click(Sender: TObject);
begin
  // Set new system scrollbar width:
  SetScrollbarWidth(40);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  // Restore original system scrollbar width:
  RestoreScrollbarWidth;
end;
Thanks, both of you.