private void UpdateScrolls()
{
// Create or dispose scrolls.
if (Rows.Count > 0)
{
if (Height < maxScrollHeight)
{
if (vScroll == null)
{
vScroll = new VScrollBar();
vScroll.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
vScroll.Height = Height;
vScroll.Location = new Point(Width - vScroll.Width, 0);
vScroll.ValueChanged += VScroll_ValueChanged;
vScroll.Visible = !vScrollHidden;
Controls.Add(vScroll);
}
}
else if (vScroll != null)
{
vScroll.ValueChanged -= VScroll_ValueChanged;
vScroll.Dispose();
vScroll = null;
ResetVOffset();
}
}
else if (vScroll != null)
{
vScroll.ValueChanged -= VScroll_ValueChanged;
vScroll.Dispose();
vScroll = null;
ResetVOffset();
}
if (Columns.Count > 0)
{
if (Width < maxScrollWidth)
{
if (hScroll == null)
{
hScroll = new HScrollBar();
hScroll.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
hScroll.Width = Width;
hScroll.Location = new Point(0, Height - hScroll.Height);
hScroll.ValueChanged += HScroll_ValueChanged;
hScroll.Visible = !hScrollHidden;
Controls.Add(hScroll);
}
}
else if (hScroll != null)
{
hScroll.ValueChanged -= HScroll_ValueChanged;
hScroll.Dispose();
hScroll = null;
ResetHOffset();
}
}
else if (vScroll != null)
{
vScroll.ValueChanged -= VScroll_ValueChanged;
vScroll.Dispose();
vScroll = null;
ResetHOffset();
}
// Update properties.
if (vScroll != null)
{
vScroll.LargeChange = (int)((float)(vScroll.Maximum - vScroll.Minimum) / ((float)maxScrollHeight / Height));
vScroll.BringToFront();
}
if (hScroll != null)
{
if (vScroll != null)
hScroll.Width = Width - vScroll.Width;
else
hScroll.Width = Width;
hScroll.LargeChange = (int)((float)(hScroll.Maximum - hScroll.Minimum) / ((float)maxScrollWidth / Width));
hScroll.BringToFront();
}
}