Hi I\'ve a tablelayoutpanel and I\'m binding controls to it dynamically. When the item count exceeds the height of panel obviously vertical scroll bar appearing there is no
I found a perfect solution about this problem by using reflect. You can try following codes:
static MethodInfo funcSetVisibleScrollbars;
static EventHandler ehResized;
public static void DisableHorizontalScrollBar(this ScrollableControl ctrl)
{
//cache the method info
if(funcSetVisibleScrollbars == null)
{
funcSetVisibleScrollbars = typeof(ScrollableControl).GetMethod("SetVisibleScrollbars",
BindingFlags.Instance | BindingFlags.NonPublic);
}
//init the resize event handler
if(ehResized == null)
{
ehResized = (s, e) =>
{
funcSetVisibleScrollbars.Invoke(s, new object[] { false, (s as ScrollableControl).VerticalScroll.Visible });
};
}
ctrl.Resize -= ehResized;
ctrl.Resize += ehResized;
}