user2181626
user2181626

Reputation:

C++ builder scrollbox component respond to mouse wheel

I was looking for an option to make mouse wheel work with scrollbox component, so far I got this

void __fastcall TForm1::ScrollBox1MouseWheelDown(TObject *Sender, TShiftState Shift,
          TPoint &MousePos, bool &Handled)
{
    Form1->ScrollBox1->VertScrollBar->Position++;
}

void __fastcall TForm1::ScrollBox1MouseWheelUp(TObject *Sender, TShiftState Shift,
          TPoint &MousePos, bool &Handled)
{
    Form1->ScrollBox1->VertScrollBar->Position--;
}

So far it works, but it scrolls really slow. Is there any way to make it scroll faster, or maybe even better way of handling scrolling in c++ builder?

Upvotes: 2

Views: 3337

Answers (2)

gabrielmdu
gabrielmdu

Reputation: 275

I use C++Builder XE2 and it doesn't support scrolling the TScrollBox natively, so I use your approach, but just the OnMouseWheel event, scrolling down if WheelDelta is lower than 0, and scrolling up if it is higher than 0.

About the scrolling speed, can't you just add/subtract a higher constant to the Position variable? Like in:

Form1->ScrollBox1->VertScrollBar->Position += 3; 

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 596592

TScrollBox in C++Builder XE2 natively supports vertical scrolling via a mouse wheel. You do not need to do anything extra to enable that behavior. I just tested it, it works fine.

Upvotes: 1

Related Questions