有什么方法可以删除 WinForms 滚动条旁边的这条白线吗?
Is there any way to remove this white line next to a WinForms scrollbar?
我注意到 System.Windows.Forms.Panel
上的滚动条似乎有一条白线向下延伸到垂直滚动条的左侧。
.
.
水平滚动条也有这个(白线出现在上面):
.
当 UseWindowsXPTheme
设置为 true 时,我也注意到 DevExpress.XtraEditors.XtraScrollableControl
,所以我猜这可能是系统问题(因为这只是一个例子,我还没有't 用 DevExpress 标签标记这个问题)。
我注意到在 Visual Studio 2015 选项屏幕中,它有一个滚动条示例,其中有这条白线(左边那条),没有它(右边那条) :
.
我的问题是:有什么办法可以去掉滚动条上的这条白线吗?如果是这样,如何?我知道这可能看起来微不足道,但它足以令人讨厌。
我已将此问题同时标记为 VB.NET 和 C#,因为我很乐意接受任何一种语言的回答。
除非您使用自己的自定义滚动控件,否则您无法执行此操作。这只是滚动条上的 3D 高亮效果,滚动条没有覆盖 属性 将其样式更改为平面。
但这里有一些您可以使用的精美自定义滚动条。
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
好吧,在研究了 之类的东西之后,我最终想出了一个更简单(但最终不舒服)的解决方案:用 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.
上进行检查
显然,如果有人使用带滚动条的可调整大小 Control
,他们会希望相应地更新 Label
大小。
我注意到 System.Windows.Forms.Panel
上的滚动条似乎有一条白线向下延伸到垂直滚动条的左侧。
水平滚动条也有这个(白线出现在上面):
当 UseWindowsXPTheme
设置为 true 时,我也注意到 DevExpress.XtraEditors.XtraScrollableControl
,所以我猜这可能是系统问题(因为这只是一个例子,我还没有't 用 DevExpress 标签标记这个问题)。
我注意到在 Visual Studio 2015 选项屏幕中,它有一个滚动条示例,其中有这条白线(左边那条),没有它(右边那条) :
我的问题是:有什么办法可以去掉滚动条上的这条白线吗?如果是这样,如何?我知道这可能看起来微不足道,但它足以令人讨厌。
我已将此问题同时标记为 VB.NET 和 C#,因为我很乐意接受任何一种语言的回答。
除非您使用自己的自定义滚动控件,否则您无法执行此操作。这只是滚动条上的 3D 高亮效果,滚动条没有覆盖 属性 将其样式更改为平面。
但这里有一些您可以使用的精美自定义滚动条。
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
好吧,在研究了 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.
上进行检查显然,如果有人使用带滚动条的可调整大小 Control
,他们会希望相应地更新 Label
大小。