0

I've built a Windows Form, in Visual Studios 2013 using C#, that has one actual Form.cs. I have a single panel in the Form.cs that I am docking/filling with UserControl.cs files as needed. The UserControls are what I am using as the actual "user input forms" for the users to fill out controls/fields and submit the needed data. I have everything working fully/correctly except for scrolling with the mouse wheel.

Here is a typical scenario that I am trying to find a solution for; When the user first navigates to one of the UserControls, they can click on a blank portion of the window and it will allow scrolling with either the vertical scroll bar on the right or with the mouse wheel. However, when the user clicks into any control within the UserControl, a textbox, a listbox, a combobox, etc., the mouse scroll will no longer scroll the window. I have not been able to find how to allow mouse wheel scrolling by moving the focus off of the control/field and onto the UserControls background or other location to aloow the users mouse wheel to scroll the window.

One thing I must make clear is the UserControls do have the vertical scroll bar available so the user can click on the scroll bar to move the window up/down, so this portion is not an issue. I have just not been able to find a way to allow the user to scroll using the mouse wheel after they click on any control/field in the UserControl "form". How can I move the focus off of any control/field and onto the UserControls background or other location to allow the mouse wheel to scroll the window/form/UserControl?

Edit: I have AutoScroll set to False on the Form.cs and the docked panel, however, I have AutoScroll set to True on each of the UserControls. This allows the right-hand scrollbar to render and be used however this does not seem to have any affect on the mouse-scrolling. I've tried every combination of setting the AutoScroll without success.

Edit(2): * * Form - panel1 ^ UserControl1.cs ^ UserControl2.cs ^ UserControl3.cs ^ UserControl4.cs ^ UserControl5.cs

Each UserControl gets applied to/rendered on panel1, based on user options. Each UserControl has the vertical scrollbar rendering on the right-hand side. Mouse-scrolling is not functioning after user clicks on/selects any control (textbox, listbox, combobox) to enter/select data. Whatever control is clicked and has focus, the focus is not moving to allow the mouse wheel to scroll the window.

  • Please show the structure of your controls better, for example using a diagram or a bullet list. It's unclear which control you expect shows scrollbar or scroll by mouse wheel. – Reza Aghaei Sep 17 '18 at 15:35

1 Answers1

0

This is not the most ideal answer I think but you could add Form.Focus(); to the Scroll event of every Control in your Form.

  • Thanks for this suggestion however when I tried this it had no affect and did not allow mouse-scrolling. I had to use the right-hand scrollbar to get the code to fire. The mouse-wheel does not fire the scroll event. – S. Wiederkehr Sep 17 '18 at 15:04
  • You could try it with the MouseWheel Event. This Event fires even if nothing "scrollable" is on the focused Control. – AustrianHunter Sep 17 '18 at 15:12
  • Once again, thank you for the suggestion however I'm not finding a MouseWheel event on the Form.cs, panle1 or on any of the UserControl.cs or any of the other controls. I've looked under the Mouse Up/Down, Mouse Click/DoubleClick, Mouse Enter/Leave & Mouse Hover/Move event options however none of these affect or fire a mouse-scrolling event. – S. Wiederkehr Sep 17 '18 at 15:35
  • Yeah you have to add it manually to the controls i think: control.MouseWheel += function; – AustrianHunter Sep 17 '18 at 15:37