Customize Windows Form Scrollbar

后端 未结 2 1969
-上瘾入骨i
-上瘾入骨i 2020-12-06 11:46

I have searched the world wide web without a proper answer.

In my Windows Form application, i want to change the width of a scrollbar that belongs to a FlowLayoutPan

2条回答
  •  -上瘾入骨i
    2020-12-06 12:24

    No, there's no way to change the width of a scrollbar displayed on a single control (although there is a system-wide setting that will affect all scrollbars in all applications).

    The ugly truth is that the lowly scrollbar control is far more complicated than it looks. Basically, the scrollbars on the FlowLayoutPanel are drawn by Windows itself (rather than the .NET Framework) because of the WS_HSCROLL and/or WS_VSCROLL window styles that are set for the control behind the scenes. The FlowLayoutPanel doesn't provide any facility to change or modify how these built-in scrollbars are drawn. Unlike other more advanced modifications in WinForms, there are no such messages we can send to the control's window procedure. And to make matters worse, the scrollbars are drawn in the non-client area of the FlowLayoutPanel, which means we can't just override its Paint event and handle drawing the scrollbars ourselves.

    Unfortunately, if you really want to customize your scrollbars, you're going to have to hide the built-in scrollbars and roll your own. It's not quite as difficult as it sounds, though, if you're up for it. This article on CodeProject provides a good walk-through on creating your own skinnable scrollbar as a user control and use it as a replacement in the container control of your choice.

提交回复
热议问题