Interminable Interminable - 6 months ago 33 Question

Is there any way to remove this white line next to a WinForms scrollbar?

I've noticed that the scrollbar on the

appears to have a white line going down the left-side of the vertical scrollbar.

Vertical scrollbar

Vertical scrollbar zoomed in

The horizontal scrollbar also has this (the white line appears above it):
Horizontal scrollbar

I've also noticed it with
when it's got
set to true, so I'm guessing it may be a system thing (as this is just an example, I haven't tagged this question with the DevExpress tag).

I've noticed that in the Visual Studio 2015 Options screen, it has an example of a Scrollbar with this white line (the one on the left), AND without it (the one on the right):
VS2015 Options

My question is: Is there any way to remove this white line from the scrollbar? If so, how? I know it may seem minor, but it's noticeable enough to be annoying.

I've tagged this question as both VB.NET and C# as I am happy to accept answers in either language.


Well, after looking into things such as handling the Paint event for a Scrollbar control, I eventually came up with an easier and simpler (but ultimately uncomfortable) solution: Cover it with a Label control!

This will do the trick for vertical and horizontal scrollbars for a Panel:

Dim key As Microsoft.Win32.RegistryKey =  Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion")
Dim operatingSystem As String = ""

If key IsNot Nothing
    operatingSystem = key.GetValue("ProductName")
End If

If operatingSystem.Contains("Windows 10")
    Dim verticalHiderLabel As New Label With {  .Location = New Point(Panel1.Right - SystemInformation.VerticalScrollBarWidth-1, Panel1.Top+1),
                                                .Size = New Size(1, Panel1.Height - SystemInformation.HorizontalScrollBarHeight-1)}

    Dim horizontalHiderLabel As New Label With {.Location = New Point(Panel1.Left+1, Panel1.Bottom - SystemInformation.HorizontalScrollBarHeight-1),
                                                .Size = New Size(Panel1.Width - SystemInformation.VerticalScrollBarWidth-1, 1)}

End If

As I've not seen this issue on any other operating systems, I've added a check to try and ensure that it's only enabled on Windows 10, which unfortunately uses the registry, as I'm not sure there's a reliable way to do that check otherwise on Windows 10.

Obviously if someone's using a resizeable Control with scrollbars, they'll want to update the Label sizes accordingly.