有什么方法可以删除WinForms滚动条旁边的白线? [英] Is there any way to remove this white line next to a WinForms scrollbar?

查看:100
本文介绍了有什么方法可以删除WinForms滚动条旁边的白线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到System.Windows.Forms.Panel上的滚动条在垂直滚动条的左侧似乎有一条白线.

水平滚动条也具有此功能(白线显示在其上方):

UseWindowsXPTheme设置为true时,我也注意到了DevExpress.XtraEditors.XtraScrollableControl,所以我猜测这可能是系统问题(因为这只是一个示例,我没有使用DevExpress标签).

我注意到,在Visual Studio 2015的选项"屏幕中,它有一个滚动条的示例,该滚动条带有此白线(左侧的一条),而没有白线(右侧的一条):

我的问题是:有什么方法可以从滚动条中删除该白线?如果是这样,怎么办?我知道这似乎不太重要,但足以引起恼人.

我已将此问题标记为VB.NET和C#,因为我很高兴接受任何一种语言的答案.

解决方案

好吧,在研究了诸如为Scrollbar控件处理Paint事件,我最终想出了一个更简单,更简单(但最终不舒服)的解决方案:用Label控件覆盖它!

这将为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

由于我没有在任何其他操作系统上看到此问题,因此我添加了一项检查以尝试确保仅在Windows 10上启用了该功能,不幸的是,该Windows 10使用了注册表,因为我不确定是否存在可靠的操作系统.在Windows 10上进行其他检查的方法

很显然,如果某人正在使用带有滚动条的可调整大小的Control,则他们将希望相应地更新Label大小.

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.

.

.

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

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): .

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

    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.

这篇关于有什么方法可以删除WinForms滚动条旁边的白线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆