0

As this is already asked and answered here how to get smartphone like scrolling for a winforms touchscreen app ( scrolling panel )

i have a problem with the solution. it only works if i click on the panel directly and scroll. If i have elements like labels/textboxes all over the place it doesnt work. I would need to click in between the Elements so i touch the panel directly. So how would i now solve this? Add a Mouse Move/Down Method on ALL elements i have within the panel?

Progman
  • 16,827
  • 6
  • 33
  • 48
deintag
  • 23
  • 4
  • 1
    [Possible duplicate](https://stackoverflow.com/q/804374/1997232). – Sinatr Jul 16 '21 at 11:24
  • See the IMessageFilter implementation here: [Hiding the Scrollbar while allowing scrolling with the Mouse Wheel in a FlowLayoutPanel](https://stackoverflow.com/a/67855814/7444103). Based on the question's scope, it handles `WM_MOUSEWHEEL`, `WM_MOUSEHWHEEL` to scroll a Parent Container (Panel, FlowLayoutPanel or any other scrollable container) which is fully covered by child Controls and `WM_LBUTTONDOWN` (to know which child Control - or nested child Control - was clicked, without handling the MouseDown event of each nested Control). You can of course trap any other message. – Jimi Jul 16 '21 at 14:02

1 Answers1

0

Use the same event for the main panel for all in-panel controls.

panel1.MouseDown += innerpanel_MouseDown;
panel1.MouseMove += innerpanel_MouseMove;
panel1.MouseUp += innerpanel_MouseUp;
foreach(Control ctr in panel1.Controls)
{
    ctr.MouseDown += innerpanel_MouseDown;
    ctr.MouseMove += innerpanel_MouseMove;
    ctr.MouseUp += innerpanel_MouseUp;
}

Events

private void innerpanel_MouseDown(object sender, MouseEventArgs e)
{
    //implementation
    Control ctr = (Control)sender;
    MessageBox.Show(ctr.Name);
}
private void innerpanel_MouseMove(object sender, MouseEventArgs e)
{
   //implementation
}
private void innerpanel_MouseUP(object sender, MouseEventArgs e)
{
  //implementation
}

Just keep in mind that if you have a button in the control panel, the button click event will run and any control that has a click event.

Meysam Asadi
  • 6,438
  • 3
  • 7
  • 17