Please run the attached sample project.
private void RadForm1_Load(object sender, EventArgs e)
{
RadScrollablePanel panel = new RadScrollablePanel() { Dock = DockStyle.Fill };
panel.BackColor = Color.Yellow;
this.Controls.Add(panel);
for (int i = 0; i < 5; i++)
{
panel.Controls.Add(new UserControl1() { Dock = DockStyle.Right, BackColor = Color.Red });
// panel.Controls.Add(new UserControl1() { Dock = DockStyle.Bottom, BackColor = Color.Red });
}
}
When the RadSplitConatiner is wide enough, the horizontal scrollbar is not shown as expected:
If you shrink the form, the horizontal scrollbar is still not shown:
However, if you dock to Left, the scrollbar is displayed:
The encountered problem is a straight consequence of the default behavior of the standard WinForms Panel. If you try the same scenario with a standard Panel you will end up with the same problem - the horizontal scrollBar is not shown, even though the form is being resized.
When designing the RadScrollablePanel our team decided to mimic the behavior of standard WinForms Panel. Unfortunately, along with all its features, RadScrollablePanel has also inherited Panel's problems.
To workaround this problem of the standard Microsoft WinForms Panel, I can suggest docking all the UserControls to the Left and use an empty Panel that occupies all the available space on the left of the form, so exactly the same behavior as all UserControls are docked to the Right. When the size of the form is changed adjust the width of the empty panel. The described approach is illustrated with the code below:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
UserControl1[] userControls;
RadScrollablePanel parentPanel;
Panel spacePanel;
public RadForm1()
{
InitializeComponent();
this.parentPanel = new RadScrollablePanel();
this.parentPanel.Dock = DockStyle.Fill;
this.parentPanel.BackColor = Color.Yellow;
this.Controls.Add(this.parentPanel);
this.parentPanel.AutoScroll = true;
int count = 10;
this.userControls = new UserControl1[count];
for (int i = 0; i < count; i++)
{
this.userControls[i] =
new UserControl1()
{
Dock = DockStyle.Left,
BackColor = Color.FromKnownColor((KnownColor)(i + 50))
};
this.parentPanel.Controls.Add(this.userControls[i]);
}
this.spacePanel = new Panel();
this.spacePanel.Dock = DockStyle.Left;
this.parentPanel.Controls.Add(this.spacePanel);
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (this.spacePanel != null)
{
int lastPanelWidth = this.parentPanel.Width;
foreach (Control control in this.parentPanel.PanelContainer.Controls)
{
if (control.Dock == DockStyle.Left && control != this.spacePanel)
{
lastPanelWidth -= control.Width;
}
}
if (lastPanelWidth < 0)
{
lastPanelWidth = 0;
}
this.spacePanel.Width = lastPanelWidth;
}
}
}
Regards,
Dimitar
Progress Telerik