Results 1 to 5 of 5

Thread: Removing the Scrollbar from a TabControl.

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Removing the Scrollbar from a TabControl.

    I am creating a custom-drawn TabControl (overriding OnPaint) and would like to know how I could remove (or hide) the scrollbar so I may add my own, custom scrollbar.

    I have tried the three methods posted here: http://stackoverflow.com/questions/2...n-details-mode to no avail. Searching Google only reveals other posts suggesting those same methods.

    Any ideas?
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Removing the Scrollbar from a TabControl.

    While I could be wrong, if everyone is suggesting the same methods and they aren't working for you then you're probably doing something wrong. Maybe if you were to show us what you're doing and tell us what's actually happening we could tell. It would be a big waste of time for everyone if we tried to come up with something else when you're simply making a mistake following the instructions you already have.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: Removing the Scrollbar from a TabControl.

    Good point, kind sir.

    I tried this:
    Code:
        Protected Overrides Sub WndProc(ByRef m As Message)
            Select Case m.Msg
                Case &H83
                    ' WM_NCCALCSIZE
                    Dim style As Integer = CInt(GetWindowLong(MeSelectedTab.Handle, GWL_STYLE))
                    If (style And WS_VSCROLL) = WS_VSCROLL Then
                        SetWindowLong(Me.SelectedTab.Handle, GWL_STYLE, style And Not WS_VSCROLL)
                    End If
                    MyBase.WndProc(m)
                    Exit Select
                Case Else
                    MyBase.WndProc(m)
                    Exit Select
            End Select
        End Sub
        Const GWL_STYLE As Integer = -16
        Const WS_VSCROLL As Integer = &H200000
    
        Public Shared Function GetWindowLong(hWnd As IntPtr, nIndex As Integer) As Integer
            If IntPtr.Size = 4 Then
                Return CInt(GetWindowLong32(hWnd, nIndex))
            Else
                Return CInt(CLng(GetWindowLongPtr64(hWnd, nIndex)))
            End If
        End Function
    
        Public Shared Function SetWindowLong(hWnd As IntPtr, nIndex As Integer, dwNewLong As Integer) As Integer
            If IntPtr.Size = 4 Then
                Return CInt(SetWindowLongPtr32(hWnd, nIndex, dwNewLong))
            Else
                Return CInt(CLng(SetWindowLongPtr64(hWnd, nIndex, dwNewLong)))
            End If
        End Function
    
        <DllImport("user32.dll", EntryPoint:="GetWindowLong", CharSet:=CharSet.Auto)> _
        Public Shared Function GetWindowLong32(hWnd As IntPtr, nIndex As Integer) As IntPtr
        End Function
    
        <DllImport("user32.dll", EntryPoint:="GetWindowLongPtr", CharSet:=CharSet.Auto)> _
        Public Shared Function GetWindowLongPtr64(hWnd As IntPtr, nIndex As Integer) As IntPtr
        End Function
    
        <DllImport("user32.dll", EntryPoint:="SetWindowLong", CharSet:=CharSet.Auto)> _
        Public Shared Function SetWindowLongPtr32(hWnd As IntPtr, nIndex As Integer, dwNewLong As Integer) As IntPtr
        End Function
    
        <DllImport("user32.dll", EntryPoint:="SetWindowLongPtr", CharSet:=CharSet.Auto)> _
        Public Shared Function SetWindowLongPtr64(hWnd As IntPtr, nIndex As Integer, dwNewLong As Integer) As IntPtr
        End Function
    No error, it just didn't work.

    I tried:
    Code:
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(hWnd As IntPtr, Msg As UInt32, wParam As Integer, lParam As Integer) As IntPtr
        End Function
    
        Private Const WM_VSCROLL As Integer = &H115
        Private Const SB_LINEDOWN As Integer = 1
    
        Protected Overrides Sub OnResize(e As EventArgs)
            MyBase.OnResize(e)
    
            SendMessage(Me.SelectedTab.Handle, WM_VSCROLL, SB_LINEDOWN, 0)
        End Sub
    And got the following Call Stack:
    at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
    at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSeri alizationManager manager, String name, CodeExpression expression)
    at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSeri alizationManager manager, String name, CodeExpression expression)
    at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSeria lizationManager manager, CodeStatement statement)

    I tried:
    Code:
        <DllImport("user32.dll")> _
        Private Shared Function ShowScrollBar(hWnd As IntPtr, wBar As Integer, bShow As Boolean) As Boolean
        End Function
    
        Protected Overrides Sub OnResize(e As EventArgs)
            MyBase.OnResize(e)
    
            ShowScrollBar(Me.SelectedTab.Handle, 3, False)
        End Sub
    And got the following Call Stack:
    at Pandora.TabControl.OnResize(EventArgs e) in C:\Users\Troy Lundin\Documents\Visual Studio 2012\Projects\_Emulation\_Pandora\TabControl.vb:line 98
    at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
    at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
    at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height)
    at System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
    at System.Windows.Forms.Control.SetBounds(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
    at System.Windows.Forms.Control.set_Size(Size value)
    at System.Windows.Forms.TabControl.UpdateSize()
    at System.Windows.Forms.TabControl.OnFontChanged(EventArgs e)
    at Pandora.TabControl.OnFontChanged(EventArgs e) in C:\Users\Troy Lundin\Documents\Visual Studio 2012\Projects\_Emulation\_Pandora\TabControl.vb:line 124
    at System.Windows.Forms.Control.set_Font(Font value)
    at Pandora.TabControl.InitializeComponent() in C:\Users\Troy Lundin\Documents\Visual Studio 2012\Projects\_Emulation\_Pandora\TabControl.Designer.vb:line 30
    at Pandora.TabControl..ctor() in C:\Users\Troy Lundin\Documents\Visual Studio 2012\Projects\_Emulation\_Pandora\TabControl.vb:line 111
    If I place "ShowScrollBar(Me.SelectedTab.Handle, 3, False)" in OnPaint, the scrollbar will disappear until the tab scrolls, which makes the scrollbar reappear. Is there another method I could put the line of code in to make the vanishing act more permanent?

    Thanks.

    Edit: The reason it wasn't working was because I was using Me.Handle instead of the correct Me.SelectedTab.Handle. /facepalm
    Prefix has no suffix, but suffix has a prefix.

  4. #4

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: Removing the Scrollbar from a TabControl.

    I am talking about the ScrollBar that appears in the tab when controls are out of view. I want to hide the default one so I can use my own. In my previous post, I explained that I figured out how to hide it, but cannot figure out where to place the code so that it doesn't reappear.
    Prefix has no suffix, but suffix has a prefix.

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Removing the Scrollbar from a TabControl.

    Oh, I thought setting autoscroll to false would hide those scrollbars, guess not.
    Me too. Just checked. It does.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width