Take a TComboBox
and put it on a TScrollBox
. In the OnMouseWheel
event of the TScrollBox
, the position of the vertical scroll bar is adjusted as follows:
void __fastcall TForm1::ScrollBox1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
TPoint &MousePos, bool &Handled)
{
ScrollBox1->VertScrollBar->Position = ScrollBox1->VertScrollBar->Position - WheelDelta;
Handled = true;
}
If the drop-down list of the TComboBox
is expanded, and you scroll outside the TComboBox
with the mouse wheel, the TComboBox
moves, but the drop-down list remains at the previous position.
I found an old-fashioned Windows 10 OS form and the TComboBox
there shows the same behavior, so this seems to be default.
A simple way is to set the DroppedDown
property of the TComboBox
in the OnMouseWheel
event to false. However, the TComboBox
is not known in the actual application. So you would have to search for a corresponding TComboBox
in the control list of the TScrollBox
.
Ideally, the behavior should be like the default behavior when you click something outside the TComboBox
, which hides the drop-down list. Unfortunately, I couldn't figure out how this is implemented in the VCL.
Do you have an idea how this could be realized?