How do I disable the horizontal scrollbar in a Panel

前端 未结 11 1915
别那么骄傲
别那么骄傲 2020-12-01 12:13

I have a panel (Windows Forms) and I want to disable a panels horizontal scrollbar. I tried this:

HorizontalScroll.Enabled = false;

But tha

11条回答
  •  春和景丽
    2020-12-01 12:41

    I just encountered this same kind of glitch with a scrollable UserControl in a form when switching from scrolling mode to zoom-to-fit mode. For the latter mode, both scrollbars should be off. Most of the time this change of mode works perfectly, except when either or both scrollbars are at their maximum value, causing one or other of the scrollbars to remain visible but disabled.

    Which of the scrollbars remains visible seems to be random, so there must be some kind of race condition in the Windows code.

    Curiously, the ClientRectangle reported by Windows is the full rectangle of the UserControl without any scrollbars. This means Windows thinks that the scrollbars are not visible, yet it still randomly displays one or other disabled scrollbar.

    I solved it by moving the AutoScrollPosition to (0, 0) before performing the switch to zoom-to-fit mode.

    AutoScrollPosition = new Point(0, 0);  // Bug fix to prevent one or other of the scrollbars randomly remaining visible when switching to zoom-to-fit mode when the scrollbars are at their maximum values.
    zoom_factor = CalcZoomFactorBestFit();
    SetScrollSizes();
    Invalidate();
    

提交回复
热议问题