scrolling a TScrollBox using the mouse

HI

is there a way to make a TScrollbox scroll (vertically) as a response to the mouse wheel?
tracking property means to scroll as the scrollbar moves but it has no relation to the mouse wheel
please advice
thanks
0
amos
7/31/2009 10:57:55 AM
embarcadero.delphi.vcl.using 2297 articles. 2 followers. Follow

12 Replies
6019 Views

Similar Articles

[PageSpeed] 33

Of course there is a way. But you've to inherit. You can try the idea if you add a  TCrollBox to a new form. 


Add the following event (I've typed in the code not copied, so there can be error in it):

[code]
public
  procedure CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL;

procedure TForm1.CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL;
begin
  Scrollbox1.VertScrollBar.Position:=Scrollbox1.VertScrollBar.Position-message.wheelDelta {div most probably wheel_delta - or leave it};
end;
{code}

Sorry but U can't make [code] or {code} to work :(

Edited by: Csaba Meszaros on Jul 31, 2009 2:54 PM

Edited by: Csaba Meszaros on Jul 31, 2009 2:55 PM
0
Csaba
7/31/2009 12:55:47 PM
amos szust wrote:

> HI
> 
> is there a way to make a TScrollbox scroll (vertically) as a response
> to the mouse wheel?  tracking property means to scroll as the
> scrollbar moves but it has no relation to the mouse wheel please
> advice thanks

Scrolling a scrollbox using the mouse wheel

The main problem seems to be that  the scrollbox does not take focus
when clicked on, and the MS Intellimouse driver will only send
WM_MOUSEWHEEL messages to the control with focus. So the messages go to
the form. The default handling in the VCL will only forward them to the
control with focus either, so no joy here as well. 

You can use the forms OnMouseWheel event to fix this behaviour:

procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
Var
  msg: Cardinal;
  code: Cardinal;
  i, n: Integer;
begin
  If WindowFromPoint( mouse.Cursorpos ) = scrollbox1.Handle Then Begin
    Handled := true;
    If ssShift In Shift Then
      msg := WM_HSCROLL
    Else
      msg := WM_VSCROLL;

    If WheelDelta < 0 Then
      code := SB_LINEUP
    Else
      code := SB_LINEDOWN;

    n:= Mouse.WheelScrollLines;
    For i:= 1 to n Do
      scrollbox1.Perform( msg, code, 0 );
    scrollbox1.Perform( msg, SB_ENDSCROLL, 0 );
  End;
end;

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
7/31/2009 6:36:31 PM
> Sorry but U can't make [code] to work :(


Use "{"code"}" (without the quotes). Use the same "{"code"}" above and below the block of code, like this (notice, the opening and closing code tags are exactly the same - there's no "close tag" marker like in XML or HTML):

{code}
var
  Test: string;
begin
  Test := 'This is a test';
end;
{code}
0
Ken
7/31/2009 8:29:07 PM
> {quote:title=Peter Below wrote:}{quote}
> amos szust wrote:
> 
> > HI
> > 
> > is there a way to make a TScrollbox scroll (vertically) as a response
> > to the mouse wheel?  tracking property means to scroll as the
> > scrollbar moves but it has no relation to the mouse wheel please
> > advice thanks
> 
> Scrolling a scrollbox using the mouse wheel
> 
> The main problem seems to be that  the scrollbox does not take focus
> when clicked on, and the MS Intellimouse driver will only send
> WM_MOUSEWHEEL messages to the control with focus. So the messages go to
> the form. The default handling in the VCL will only forward them to the
> control with focus either, so no joy here as well. 
> 
> You can use the forms OnMouseWheel event to fix this behaviour:
> 
> procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
>   WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
> Var
>   msg: Cardinal;
>   code: Cardinal;
>   i, n: Integer;
> begin
>   If WindowFromPoint( mouse.Cursorpos ) = scrollbox1.Handle Then Begin
>     Handled := true;
>     If ssShift In Shift Then
>       msg := WM_HSCROLL
>     Else
>       msg := WM_VSCROLL;
> 
>     If WheelDelta < 0 Then
>       code := SB_LINEUP
>     Else
>       code := SB_LINEDOWN;
> 
>     n:= Mouse.WheelScrollLines;
>     For i:= 1 to n Do
>       scrollbox1.Perform( msg, code, 0 );
>     scrollbox1.Perform( msg, SB_ENDSCROLL, 0 );
>   End;
> end;
> 
> -- 
> Peter Below (TeamB)  
> Don't be a vampire (http://slash7.com/pages/vampires), 
> use the newsgroup archives :
> http://codenewsfast.com
> http://groups.google.com

i added the above code into the mentioned event but it doesnt seem to be triggered at all
the scrollbox is aligned client to the form but the event is not triggered
0
amos
8/1/2009 9:58:51 AM
amos szust wrote:

> i added the above code into the mentioned event but it doesnt seem to
> be triggered at all the scrollbox is aligned client to the form but
> the event is not triggered

What does the scrollbox contain? There may be a problem if there is
nothing on the form that takes the focus.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
8/2/2009 8:28:45 AM
> {quote:title=Peter Below wrote:}{quote}
> amos szust wrote:
> 
> > i added the above code into the mentioned event but it doesnt seem to
> > be triggered at all the scrollbox is aligned client to the form but
> > the event is not triggered
> 
> What does the scrollbox contain? There may be a problem if there is
> nothing on the form that takes the focus.
> 
> -- 
> Peter Below (TeamB)  
> Don't be a vampire (http://slash7.com/pages/vampires), 
> use the newsgroup archives :
> http://codenewsfast.com
> http://groups.google.com

on the form i have a panel which is aligned top and a scrollbox which is aligned client.
on the scrollbox i create at runtime a lot of labels
the panel contains a label and a TEdit

the form is placed inside a tabsheet so maybe that can explain the problem?
0
amos
8/2/2009 7:18:36 PM
amos szust wrote:

> on the form i have a panel which is aligned top and a scrollbox which
> is aligned client.  on the scrollbox i create at runtime a lot of
> labels the panel contains a label and a TEdit
> 
> the form is placed inside a tabsheet so maybe that can explain the
> problem?

Yes, of course. This means that it is embedded into another form. It
would be the top-level forms OnMousewheel event that gets the wheel
action in this case.



-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
8/3/2009 6:18:32 PM
> {quote:title=Peter Below wrote:}{quote}
> amos szust wrote:
> 
> > on the form i have a panel which is aligned top and a scrollbox which
> > is aligned client.  on the scrollbox i create at runtime a lot of
> > labels the panel contains a label and a TEdit
> > 
> > the form is placed inside a tabsheet so maybe that can explain the
> > problem?
> 
> Yes, of course. This means that it is embedded into another form. It
> would be the top-level forms OnMousewheel event that gets the wheel
> action in this case.
> 
> 
> 
> -- 
> Peter Below (TeamB)  
> Don't be a vampire (http://slash7.com/pages/vampires), 
> use the newsgroup archives :
> http://codenewsfast.com
> http://groups.google.com

still no response from that event
0
amos
8/3/2009 7:13:52 PM
amos szust wrote:

> > {quote:title=Peter Below wrote:}{quote}
> > amos szust wrote:
> > 
> > > on the form i have a panel which is aligned top and a scrollbox
> > > which is aligned client.  on the scrollbox i create at runtime a
> > > lot of labels the panel contains a label and a TEdit
> > > 
> > > the form is placed inside a tabsheet so maybe that can explain the
> > > problem?
> > 
> > Yes, of course. This means that it is embedded into another form. It
> > would be the top-level forms OnMousewheel event that gets the wheel
> > action in this case.
> 
> still no response from that event

Pity. Windows is unfortunately a bit selective in which controls it
sends wheel messages to and you seem to have found a setup that does
not generate them. Or they get lost somewhere <g>.

Since wheel messages are posted like other mouse messages there is a
intervention point that will work whatever control has the focus, if
Windows creates the wheel message at all. That is the
Application.OnMessage event. Try that.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
8/4/2009 5:52:11 PM
Hi Peter


> Pity. Windows is unfortunately a bit selective in which controls it
> sends wheel messages to and you seem to have found a setup that does
> not generate them. Or they get lost somewhere <g>.
> 
> Since wheel messages are posted like other mouse messages there is a
> intervention point that will work whatever control has the focus, if
> Windows creates the wheel message at all. That is the
> Application.OnMessage event. Try that.


I just tried you code and it have an error.
Exchange SB_LINEDOWN/SB_LINEUP, and I changed to use im my code, like this:

<pre>
procedure TFormMain.ScrollBoxMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var
  Handled: Boolean);
var
  Msg: Cardinal;
  Code: Cardinal;
  I, ScrollLines: Integer;
begin
  if WindowFromPoint(Mouse.Cursorpos) = ScrollBox.Handle then
  begin
    Handled := True;
    Msg:= IfThen(ssShift in Shift, WM_HSCROLL, WM_VSCROLL);
    Code:= IfThen(WheelDelta < 0, SB_LINEDOWN, SB_LINEUP);
    ScrollLines:= Mouse.WheelScrollLines * 5;
    for I:= 1 to ScrollLines do
      ScrollBox.Perform(Msg, Code, 0);
    ScrollBox.Perform(Msg, SB_ENDSCROLL, 0);
  end;
end;
</pre>

Working like a charm.


--
Cesar Romero
http://www.cesarromero.com.br

Edited by: Cesar Romero on Aug 21, 2009 10:48 PM
0
Cesar
8/22/2009 5:49:52 AM
> {quote:title=amos szust wrote:}{quote}
> > {quote:title=Peter Below wrote:}{quote}
> > amos szust wrote:
> > 
> > > HI
> > > 
> > > is there a way to make a TScrollbox scroll (vertically) as a response
> > > to the mouse wheel?  tracking property means to scroll as the
> > > scrollbar moves but it has no relation to the mouse wheel please
> > > advice thanks
> > 
> > Scrolling a scrollbox using the mouse wheel
> > 
> > The main problem seems to be that  the scrollbox does not take focus
> > when clicked on, and the MS Intellimouse driver will only send
> > WM_MOUSEWHEEL messages to the control with focus. So the messages go to
> > the form. The default handling in the VCL will only forward them to the
> > control with focus either, so no joy here as well. 
> > 
> > You can use the forms OnMouseWheel event to fix this behaviour:
> > 
> > procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
> >   WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
> > Var
> >   msg: Cardinal;
> >   code: Cardinal;
> >   i, n: Integer;
> > begin
> >   If WindowFromPoint( mouse.Cursorpos ) = scrollbox1.Handle Then Begin
> >     Handled := true;
> >     If ssShift In Shift Then
> >       msg := WM_HSCROLL
> >     Else
> >       msg := WM_VSCROLL;
> > 
> >     If WheelDelta < 0 Then
> >       code := SB_LINEUP
> >     Else
> >       code := SB_LINEDOWN;
> > 
> >     n:= Mouse.WheelScrollLines;
> >     For i:= 1 to n Do
> >       scrollbox1.Perform( msg, code, 0 );
> >     scrollbox1.Perform( msg, SB_ENDSCROLL, 0 );
> >   End;
> > end;
> > 

This worked for me (although I had to reverse the scrolling direction).
However, if there was any component within the ScrollBox that could take focus (eg TStringGrid), then scrolling would stop once it moved under the mouse pointer.
To overcome this, I had to set those components Enabled := false.
This was ok for my application because the scrollbox contains only data for viewing - no input.

Phil Rogers
0
Phil
12/15/2009 2:35:07 PM
If you need input controls in your scrollBox, you can also look for the parent handle of the pointed control
{code}
procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
Var
  Msg: Cardinal;
  Code: Cardinal;
  I: Integer;
  handleSouris: HWND;

  function isChildOf(Feuille, Racine: HWND): Boolean;
  var
    Composant: TWinControl;
  begin
    if (Feuille = Self.Handle) then
      Result:= False
    else
      if (Feuille = Racine) then
        Result:= True
      else
      begin
        Composant:= FindControl(Feuille);
        Result:= Assigned(Composant) and Assigned(Composant.Parent) and isChildOf(Composant.Parent.Handle, Racine);
      end;
  end;

begin
  if (isChildOf(WindowFromPoint(Mouse.CursorPos), ScrollBox1.Handle)) then
  begin
    Handled:= True;
    if (ssShift in Shift) then
      Msg := WM_HSCROLL
    else
      Msg := WM_VSCROLL;
    if (WheelDelta < 0) then
      Code := SB_LINEDOWN
    else
      Code := SB_LINEUP;
    for I:= 1 to Mouse.WheelScrollLines do
      ScrollBox1.Perform(Msg, Code, 0);
    ScrollBox1.Perform(Msg, SB_ENDSCROLL, 0);
  end;
end;
{code}
0
Elias
1/8/2010 12:59:12 PM
Reply:

Similar Artilces:

To use or not to use Delphi
Sadly, it seems to me that there is a sort of race between the two threads, for and against using Delphi in new projects, with more or less the same users posting in both threads. Arguments are fiercely debated in both camps. Borland had their own vision. As a community, now that Delphi has changed ownership I believe we should try to be more consistent, more clear, and more articulate in what we expect from Embercadero in terms of Delphi. We can contribute to keeping Delphi alive and moving in the right direction. "Laurent Cocea" schrieb: > Sadly, it seems to me that there ...

When to use ( and when to use ((?
I'm just not getting it. When do you use ( in a statement, when do you need to use ((, and is the space after either or both mandatory? For example, I coded this statement: if (( $_ eq $bad_guys_ip )) { more_stuff_here }; Why the two (( in an if? And why does it seem to not work when I miss the space after the ((? Thanx! Mark me as... /Corn-fused|Dense/ > I'm just not getting it. >=20 > When do you use ( in a statement, when do you need to use ((, and is > the space after either or both mandatory? >=20 > For example, I coded this sta...

Using Using
I have just completed reading a chapter in my book on performance. The books says to speed up performance on your web site you should use the using statement when opening connections. My question is how do you catch errors if you are using this as apposed to a try catch block.thanksBryan  Why would you use it as an alternative to a try/catch statement. Couldn't you just do something like  public void UsingSomeMethod() { try { SomeMethod(); } catch(SomeException e) { /// do something useful }}public void SomeMethod() { using (Something) { ...

Using a Scroll Wheel Mouse with Delphi 3
May well be a better way -- but if you use an old version of Delphi 3 like I do, you can make the IDE recognize your mouse's scroll wheel by downloading a free program called "HotMouse" and installing it. By force of habit, I was always spinning the scroll wheel to move around in my editor window. With this little program installed, it works now! Curt Carpenter wrote: > May well be a better way -- but if you use an old version of Delphi 3 > like I do, you can make the IDE recognize your mouse's scroll wheel > by downloading a free program called "HotMo...

How to use the arguments to use() in the package being used
Howdy,=20 The subject says it all believe it or not :) What I'm trying to figure out is how to pass an argument=20 (pragma I believe is the proper term) to use() and do=20 sonethign in the package based on it. I've looked at CGI.pm source but can't seem to track it down.=20 (Similar idea as to CGIs -oldstyle_urls -newstyel_urls) http://search.cpan.org/~lds/CGI.pm-3.04/CGI.pm#PRAGMAS What I'd like to do is something like this: # for old time's sake we'll just use our favorite module use Foo::Monkey qw(:Foo :Bar -doamazingthings); #then in Foo::Monkey...

Any mouse event being triggered when using the mouse scroll button!
Hi all I'd like to know if there is any event being triggered when you roll the mouse scroll button! (Other than the pbm_dwnvscroll, pbm_dwnhscroll) Thanks Stelios Stylianou ...

How design a COM using Delphi and Using in PB7?
I need some component, So, we want using DELPHI5 to develop a COM or Activex. What type of knowege or Skill I must know it. Can anyone tell us? from DRAOGN Can you explain what type of component you want to create? You may not need to a) build your own, or b) use Delphi. If the component should be used from within a PB application, you ought to use PB to develop it unless it is something that PB does not let you do. regards, Bill DRAGON wrote: > I need some component, So, we want using DELPHI5 to develop a COM or > Activex. > What type of knowege or Skill I ...

why to use 1)use CGI,2)use Strict ,3)use Carp in script
hi why we r using 1)use CGI, 2)use Strict, 3)use Carp in the begining of script sometimes. What is the use of it.Is the files CGI.pm,Strict.pm,Carp.pm default with PERL. Thnx __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com On Thu, 2004-11-04 at 09:31, supriya devburman wrote: > hi Hi > why we r using > 1)use CGI, We only use CGI when we want to use methods from that module (usually on web pages); see `perldoc CGI` for more information on what you...

I used to use Firefox until...
Name: Dan Product: Firefox Summary: I used to use Firefox until... Comments: Firefox takes forever to load now, even the absolute newest version. It has become clunky and everyone I know has moved on to another browser. I prefer Chrome. I suggest adding some sort of configuration optimization tool as well as toolbar/add-on install/hijack prevention. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a re...

scroll by using mouse wheel
My window is too large and lots of control on it. At runtime I want scroll to vertical and horizontal using mouse wheel. How can do this folks? afaik the mouseweel works fine in PB. when the window has a scroll bar it should work. but horizontally? can your wheel scroll horizontally? "Raj" <rchilamula@crimes.net> schreef in bericht news:e3njzRrNDHA.362@forums-2-dub... > My window is too large and lots of control on it. At runtime I want scroll > to vertical and horizontal using mouse wheel. How can do this folks? > > Sure, inthe PB IDE if t...

How to use net use?
Please can any one tell me how to use the dos command net use properly? I have read the help but can't seem to get it to work. Keep getting sytax error message. Thanks in advance. "Beowulf" <who-knows@no-one.com> wrote in message news:9krutk$puu$1@news.grc.com... > Please can any one tell me how to use the dos command net use properly? > > I have read the help but can't seem to get it to work. Keep getting sytax > error message. what are you trying to do? There are about 50 options to "net use" that do a ton of different thin...

To use signatures or not to use?
--001a11c3871a8a8fe2051b7b8b18 Content-Type: text/plain; charset=UTF-8 Dear all, Perl now has subroutine signatures. However, they are marked as experimental feature. As I really like it, I'm always tempted to use it. On the other hand, I don't want to wast efforts to something I have to roll back. So, does anyone know the tendency if signatures are going to stay? I'm not looking for the standard "do if you want to do it because TIMTOWTDI" answer, it will not help me. I'm looking for rumors, or eventually an assessment from the people who did the fe...

Why using use strict;
Hi all, I know why I should use "use strict;" but what happen if I use "use strict;" then if the code is OK, I delete this line? Shouldn't it work the same without this line if the code has no problems? Thanks. Teddy, orasnita@home.ro why would you want to do that Octavian? "use strict" is a sanity safety net. What your saying is like "I know why I should use safety belt whilst driving my car but what if I took it off?" - of course you can do it but beware of the consequences. joel -----Original Message----- From: ...

To use DNN or not to use?
Hello,I am developing a community web based appication for non-profits and social service agencies in our county, that will be used to provide and track client services in a single datastore.Some built in features that dnn has is what I need, but I need custom tree navigation, list views, edit on the fly, several customized layers for data access, etc.I am familiar with asp.net, but not very familiar with dnn.  I installed  dnn on a friends website but never had time to configure and learn more about it.What are the general rules when deciding when to use dnn and when not...

Web resources about - scrolling a TScrollBox using the mouse - embarcadero.delphi.vcl.using

Resources last updated: 1/22/2016 2:09:09 PM