Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9565
  • Last Modified:

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.
0
mullet_attack
Asked:
mullet_attack
  • 3
  • 3
  • 2
  • +1
1 Solution
 
kretzschmarCommented:
where is the scrollbar->which control?
which delphi version do you use?
0
 
CynnaCommented:
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.
0
 
kretzschmarCommented:
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 ;-)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
CynnaCommented:
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... :)

0
 
mullet_attackAuthor Commented:
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.
0
 
Lee_NoverCommented:
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
0
 
mullet_attackAuthor Commented:
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?
0
 
Lee_NoverCommented:
> as the application may be used on a touch screen <
sorry, didn't see that part
but you did ask for all of our opinions .. anyway back to your problem

if you do change the system scrollbar width then you should have it as an option

to set the system scrollbar widths use :

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;


not tested but it should work
1
 
CynnaCommented:
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;
1
 
mullet_attackAuthor Commented:
Thanks, both of you.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now