luebbe 26 Posted November 15, 2021 Hi Folks, I'm stuck with the problem that I want to prevent a grid to act on the mouse wheel events. The UI layout is the following: On a TFrame (created at runtime) I have a TCategoryPanelGroup. As the application is receiving data in different formats, for each data package a new TCategoryPanel is created at runtime and placed on the TCategoryPanelGroup. Each TCategoryPanel contains two grids who are adjusted to fit the data. The heights of the grids and the TCategoryPanel are adjusted so that in >90% of the cases the grids won't have a scrollbar. Now when I use the mouse wheel over a grid, the grid catches the wheel and happily acts on it, which is not what I want. If the grid has a scrollbar (rare case), the user shall use the scrollbar to scroll the grid. My goal is to always scroll the TCategroyPanelGroup when the mouse wheel is used over one of the grids or a TCategorypanel so the user can quickly flip through the categories. How can I make the grids and the TCategoryPanel "ignore" or "pass up" the mouse wheel events so that the TCategoryPanelGroup receives them and can act on them? Would a different structure of UI elements be a better approach? I'm actually quite happy with the category panels, because the data inside can be clearly identified via their header and they can be collapsed when I don't want to see all different data sets at the same time. I've attached a stripped example of the UI structure that just catches the mouse wheel events for the controls and outputs them in a memo. MouseScroll.zip Share this post Link to post
dwrbudr 8 Posted November 15, 2021 procedure TMyGrame.MouseWheelHandler(var Msg: TMessage); var Control: TWinControl; pt: TPoint; begin Pt.X := SmallInt(Msg.lParam); Pt.Y := SmallInt(HiWord(Msg.lParam)); Control := FindVCLWindow(Pt); if Assigned(Control) then begin if (Control is TGrid) then begin Msg.Result := 1; end else begin Control.DefaultHandler(Msg); end; end else begin inherited MouseWheelHandler(Msg); end; end; Does it help if you override MouseWheelHandler as the code snippet above? Share this post Link to post
luebbe 26 Posted November 15, 2021 Sorry no, it doesn't help. The stringgrid still catches all mouse wheel events. And there is a stack overflow in TControl.Defaulthandler when I'm not over a grid. Share this post Link to post