Board index » delphi » Manual Scrolling/scroll bars

Manual Scrolling/scroll bars

Does anyone know how to override the automatic scroll bar in order to scroll
with a key press?  For example, the ListView class automatically scrolls
left and right with the press of the left/right keys, however the TreeView
does not.  I want to re-map the left/right keys on the TreeView from
collapsing/expanding to scrolling left and right as if you had clicked the
scroll bar arrows with the mouse.
 

Re:Manual Scrolling/scroll bars


Quote
"Phil Hoffman" <p...@spencertechnologies.com> wrote in message

news:3b4a119e$1_1@dnews...

Quote
> Does anyone know how to override the automatic scroll bar in order to
scroll
> with a key press?  For example, the ListView class automatically scrolls
> left and right with the press of the left/right keys, however the TreeView
> does not.  I want to re-map the left/right keys on the TreeView from
> collapsing/expanding to scrolling left and right as if you had clicked the
> scroll bar arrows with the mouse.

Are Ctrl+Left, Ctrl+Right not working?

--
Regards,
Chris Luck

Re:Manual Scrolling/scroll bars


Quote
In article <3b4a119e$1_1@dnews>, Phil Hoffman wrote:
> Does anyone know how to override the automatic scroll bar in order to scroll
> with a key press?  For example, the ListView class automatically scrolls
> left and right with the press of the left/right keys, however the TreeView
> does not.  I want to re-map the left/right keys on the TreeView from
> collapsing/expanding to scrolling left and right as if you had clicked the
> scroll bar arrows with the mouse.

You can scroll a control in code by sending WM_HSCROLL (for the horizontal
scrollbar) messages to it, e.g.

  treeview1.perform( WM_HSCROLL, SB_LINELEFT, 0 );
  treeview1.perform( WM_HSCROLL, SB_ENDSCROLL, 0 );

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Manual Scrolling/scroll bars


They do work, however what I would then need to do is generate a Ctrl+Left
or Right keyboard event.  I can only use keyboard controls in my app, and it
is for a custom keypad so there is no control key, nor can I map another key
to Ctrl.  So what I need to do is generate Ctrl+Left.  I know of the
OnKeyDown handler, and also I'm using KeyPreview = True in my form, but I
can't seem to properly generate the keyboard events that I need to.

Quote
Chris Luck <ch...@bvhg.freeXXserve.co.uk> wrote in message

news:3b4bf3b0_1@dnews...
Quote
> "Phil Hoffman" <p...@spencertechnologies.com> wrote in message
> news:3b4a119e$1_1@dnews...
> > Does anyone know how to override the automatic scroll bar in order to
> scroll
> > with a key press?  For example, the ListView class automatically scrolls
> > left and right with the press of the left/right keys, however the
TreeView
> > does not.  I want to re-map the left/right keys on the TreeView from
> > collapsing/expanding to scrolling left and right as if you had clicked
the
> > scroll bar arrows with the mouse.

> Are Ctrl+Left, Ctrl+Right not working?

> --
> Regards,
> Chris Luck

Re:Manual Scrolling/scroll bars


"Peter Below (TeamB)" <100113.1...@compuXXserve.com> wrote in message
news:VA.0000746f.004b3d51@antispam.compuserve.com...

Quote
> You can scroll a control in code by sending WM_HSCROLL (for the horizontal
> scrollbar) messages to it, e.g.

>   treeview1.perform( WM_HSCROLL, SB_LINELEFT, 0 );
>   treeview1.perform( WM_HSCROLL, SB_ENDSCROLL, 0 );

Is the EndScroll required?  I haven't (yet) hit a problem using only the
line messages, but then I haven't greatly exercised  them either.

--
Regards,
Chris Luck

Re:Manual Scrolling/scroll bars


Quote
"Phil Hoffman" <p...@spencertechnologies.com> wrote in message

news:3b4f4b2e$1_1@dnews...

Quote
> They do work, however what I would then need to do is generate a Ctrl+Left
> or Right keyboard event.  I can only use keyboard controls in my app, and
> it is for a custom keypad so there is no control key, nor can I map
> another key to Ctrl.  So what I need to do is generate Ctrl+Left.  I know
> of the OnKeyDown handler, and also I'm using KeyPreview = True in my form,
> but I can't seem to properly generate the keyboard events that I need to.

Wot.  No shift?  That sounds seriously constraining but, even so, you
shouldn't need to handle the keys at the form level.  Using Peters
suggestion should work for you.

procedure TForm1.TreeView1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  // if shift key is available
  if (ssShift in Shift) then
  begin
  // -------------
    case Key of
    VK_Left:
      begin
        treeview1.perform( WM_HSCROLL, SB_LINELEFT, 0 );
        Key := 0;
      end;
    VK_Right:
      begin
        treeview1.perform( WM_HSCROLL, SB_LINERIGHT, 0 );
        Key := 0;
      end;
    end;
  // -------------
  end // end shift
end;

--
Regards,
Chris Luck

Re:Manual Scrolling/scroll bars


Quote
In article <3b4f82d8_2@dnews>, Chris Luck wrote:
> >   treeview1.perform( WM_HSCROLL, SB_LINELEFT, 0 );
> >   treeview1.perform( WM_HSCROLL, SB_ENDSCROLL, 0 );

> Is the EndScroll required?

May depend on the target control. When you use a scrollbar by clicking
on the bar (not dragging) it sends an endscroll on mouse up, so some
controls may depend on it. It is like key events, for each key down
there will eventually by a key up...

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Manual Scrolling/scroll bars


"Peter Below (TeamB)" <100113.1...@compuXXserve.com> wrote in message
news:VA.00007483.014c4d5f@antispam.compuserve.com...

Quote
> > Is the EndScroll required?

> May depend on the target control. When you use a scrollbar by clicking
> on the bar (not dragging) it sends an endscroll on mouse up, so some
> controls may depend on it. It is like key events, for each key down
> there will eventually by a key up...

Win32.hlp is not at all enlightening (nor MSDN) on where it is appropriate
to use it or whether it is only relevant to mouse activation.  I'll go away
and quietly watch messages, but may I assume that non-essential Endscroll
messages do not cause a problem?

--
Regards,
Chris Luck

Re:Manual Scrolling/scroll bars


Quote
In article <3b51195f$1_2@dnews>, Chris Luck wrote:
> may I assume that non-essential Endscroll
> messages do not cause a problem?

Yes.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads