Is there any way to remove this white line next to

2019-07-26 19:47发布

I've noticed that the scrollbar on the System.Windows.Forms.Panel 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 DevExpress.XtraEditors.XtraScrollableControl when it's got UseWindowsXPTheme 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.

2条回答
闹够了就滚
2楼-- · 2019-07-26 20:15

You cannot do this unless you use your own custom controls for scrolling. This is just a 3D highlight effect on the scrollbar and the scrollbar does not have an override property to change its style to flat.

But here are some fancy custom scrollbars you can use.

CodeProject: Scrolling Panel

CodeProject: Cool Scrollbar - Scrollbar like Windows Media Player's

CodeProject: How to skin scrollbars for Panels, in C#

CodeProject: Replace a Window's Internal Scrollbar with a customdraw scrollbar Control

查看更多
欢心
3楼-- · 2019-07-26 20:19

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)}

    Me.Controls.Add(verticalHiderLabel)
    Me.Controls.Add(horizontalHiderLabel)
    verticalHiderLabel.BringToFront()
    horizontalHiderLabel.BringToFront()
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.

查看更多
登录 后发表回答