Continuous Scrolling with Panels in Panels

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Continuous Scrolling with Panels in Panels



I'm currently developing reports, which are absolutely massive, that are required to be in a certain format. For that I created a Form, and insert it multiple times into a Panel.



I was reaching the height limit on the Panel, so I separated the information into smaller categories, put those on separate panels, then put the panels into the original panel


Original Panel
Panel1
info
info
info

Panel2
info
info
info

Panel3
info
info
info




This works perfectly except for scrolling. Individual Panels scroll until they reach the bottom, then stop. I would like for the main Panel to scroll when a subPanel reaches the top or bottom.



To explain another way, the functionality found in DIVs in html. The inner DIV scrolls, and when it reaches MAX or MIN height, the parent DIV continues scrolling.



Is there a way to do this?





What are you targetting: Winforms, WPF, ASP..? YOU should always TAG your questions correctly so one can see it on the questions page!
– TaW
Aug 9 at 14:36





Sorry, edited tag to reflect Win-forms. I may have found a solution anyway. Will post it if it works correctly.
– Tyler Underwood
Aug 10 at 12:02




1 Answer
1



So, after a little experimentation, I found an answer and am posting it for anyone who needs it.


private void flowLayout_MouseWheel(object sender, MouseEventArgs e)
(currentPosition == -1*(this.flowLayoutPanel1.VerticalScroll.Maximum + 1 - this.flowLayoutPanel1.VerticalScroll.LargeChange) && e.Delta<0))

Control control = this.Parent;
FlowLayoutPanel flp = control as FlowLayoutPanel;
if(flp == null) return;

flp.VerticalScroll.Value = Math.Min(Math.Max(flp.VerticalScroll.Value - e.Delta, 0), (flp.VerticalScroll.Maximum + 1 - flp.VerticalScroll.LargeChange));





This code first gets the Current Position of the FlowLayoutPanel.


var currentPosition = this.flowLayoutPanel1.AutoScrollPosition.Y;



If e.Delta is negative, the user is scrolling down. Up is positive.


if(
(currentPosition == this.flowLayoutPanel1.VerticalScroll.Minimum
&& e.Delta>0)
|| (currentPosition == -1*(this.flowLayoutPanel1.VerticalScroll.Maximum + 1 - this.flowLayoutPanel1.VerticalScroll.LargeChange)
&& e.Delta<0)
)



If the Panel is scrolled to the top, and the user scrolls up, it gets the Parent of the form, which is the main panel. If it can't get the panel, it exits.


Control control = this.Parent;
FlowLayoutPanel flp = control as FlowLayoutPanel;
if(flp == null) return;



It then adjusts the main panel by the same delta, constraining it with Max and Min to avoid OutOfBoundsException that is caused when you try to set the value less than it's minimum or greater than it's maximum.


flp.VerticalScroll.Value = Math.Min(
Math.Max(flp.VerticalScroll.Value - e.Delta, 0),
(flp.VerticalScroll.Maximum + 1 - flp.VerticalScroll.LargeChange)
);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard