Solved

Change Scrollbar width programmatically

Posted on 2002-07-09
10
8,853 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now