How do I disable the horizontal scrollbar in a Panel

前端 未结 11 1936
别那么骄傲
别那么骄傲 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:35

    Following the code proposed by @Guesting, I have written a custom class for the panel control for enabling the double buffer option and also with possibility of enabling / disabling each scrollbar.

       Public Class PanelDoubleBuffer
        Inherits Panel
    
        'MAIN LAYOUT design scheme
        Public Property ShowVerticalScrolBar As Boolean = False
        Public Property ShowHorizontalScrolBar As Boolean = False
    
        Public Sub New()
            SuspendLayout()
    
            SetStyle(ControlStyles.AllPaintingInWmPaint, True)
            SetStyle(ControlStyles.UserPaint, True)
    
            SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
            SetStyle(ControlStyles.SupportsTransparentBackColor, True)
            SetStyle(ControlStyles.ResizeRedraw, True)
            Me.UpdateStyles()
    
            ResumeLayout()
        End Sub
    
        
        Private Shared Function ShowScrollBar(ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Boolean) As Boolean
        End Function
    
        Public Property SB_HORZ As Integer = ShowHorizontalScrolBar
        Public Property SB_VERT As Integer = ShowVerticalScrolBar
        Public Property SB_CTL As Integer = 2
        Public Property SB_BOTH As Integer = 3
    
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = &H85 Then
                ShowScrollBar(Me.Handle, CInt(SB_BOTH), False)
            End If
    
            MyBase.WndProc(m)
        End Sub
    End Class
    

提交回复
热议问题