【问题标题】:Is there any way to remove this white line next to a WinForms scrollbar?有什么方法可以删除 WinForms 滚动条旁边的这条白线?
【发布时间】:2016-06-29 09:04:36
【问题描述】:

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

.

.

水平滚动条也有这个(白线出现在它上面): .

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

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

我的问题是:有什么办法可以从滚动条中删除这条白线?如果是这样,怎么做?我知道这可能看起来微不足道,但它足以令人讨厌。

我已将此问题标记为 VB.NET 和 C#,因为我很乐意接受这两种语言的答案。

【问题讨论】:

  • 你的应用程序有Application.EnableVisualStyles();吗?
  • 好像是3d高光。不确定在哪里可以将其设置为平面样式..
  • 添加对Application.EnableVisualStyles() 的调用作为InitializeComponent() 中的第一行似乎没有任何效果。
  • 看看 program.cs 中的代码,这应该不足为奇,对吧?它更有可能在系统设置中影响它,但在我看来,这在任何情况下都是不行的..

标签: c# vb.net winforms scrollbar panel


【解决方案1】:

除非您使用自己的自定义控件进行滚动,否则您无法执行此操作。这只是滚动条上的 3D 高亮效果,滚动条没有覆盖属性来将其样式更改为平面。

但这里有一些您可以使用的精美自定义滚动条。

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

【讨论】:

    【解决方案2】:

    好吧,在研究了 handling the Paint event for a 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 的大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 2012-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多