Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created a custom control with scroll activated after 5 elements. Once the control has elements over 10 items it starts adding space to the bottom of the form..

Lets call "My Custom Control" MCC for better understanding in the explanation below.


Explanation:

MCC is a panel, stacks a set of user controls. I activate autoscroll when there are 5 or more elements in the MCC by setting the maximum size on the control. MCC is laid out on the form during run time. The form also has other controls apart from MCC. There are controls that render before and after MCC has rendered. So what adding controls to MCC does is that it adds additional blank space at the bottom of the form and I want to know i could get rid of that space. I hope this explains enough...


What I have tried:

I have tried setting the dock property to Top

*Note: I cannot set the autoscroll to false
Posted
Updated 15-Jul-19 21:07pm
v3
Comments
OriginalGriff 15-Jul-19 10:57am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Hrishikesh Shahapurkar 15-Jul-19 14:17pm    
I have added explanation to the question, please let me know if you need any more clarification.
Dave Kreskowiak 15-Jul-19 11:22am    
I don't think anyone has any clue what you're talking about. Without a better description of the problem and the circumstances under which it occurs and some code to look at, it's very unlikely you're ever going to get a useful answer.

Assuming this is Windows Forms:

1 the Form your Panel is sited on can only add space "to the bottom of the Form" ... when Controls are added to the Panel at run-time ... if the Form 'Autosize and the Panel 'AutoSize are both 'true.

Simple fix:

1 set the Panel 'Autosize to 'false, and Panel 'AutoScroll to 'true.

2 as you add Controls at run-time, set the Dock to 'Top, and call 'BringToFront(): that will ensure the order of Controls in the Panel are from first (top) to last (bottom).

Like this:
UserControl1 uc = new UserControl1();

panel1.Controls.Add(uc);

uc.Dock = DockStyle.Top;

uc.BringToFront();
This way you do not need to concern yourself about how many User Controls are in the Panel.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900