Solved

Change Scrollbar width programmatically

Posted on 2002-07-09
10
9,337 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
[X]
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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
1
 
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;
1
 
LVL 2

Author Comment

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

Featured Post

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.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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