Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Change Scrollbar width programmatically

Posted on 2002-07-09
10
9,089 Views
Last Modified: 2012-08-14
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
Comment
Question by:mullet_attack
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7140781
where is the scrollbar->which control?
which delphi version do you use?
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7141103
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7141139
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 7

Expert Comment

by:Cynna
ID: 7141556
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
 
LVL 2

Author Comment

by:mullet_attack
ID: 7142062
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
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7142183
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
 
LVL 2

Author Comment

by:mullet_attack
ID: 7142778
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
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 200 total points
ID: 7142903
> 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
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7142944
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;
0
 
LVL 2

Author Comment

by:mullet_attack
ID: 7143390
Thanks, both of you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 116
Dev Express grid collapse 2 45
firemonkey keyboard covers the controls 1 37
Firemonkey BASS_Init into a thread 17 31
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question