移除或隐藏GridView WinForms中的垂直卷轴

wko9yo5t  于 2022-11-17  发布在  其他
关注(0)|答案(2)|浏览(150)

我有一个应用程序在WinForms的POS客户端。我的客户端有一个触摸屏系统,所以我需要实现按钮滚动在GridView。
现在我面临的问题是我无法隐藏滚动条。当我试图隐藏滚动条时,出现了一个黑色的分裂图像

If TypeOf (sender) Is VScrollBar Then
                Dim scrollBar As VScrollBar = CType(sender, VScrollBar)
                If TypeOf (scrollBar.Parent) Is KryptonExtendedGrid Then
                    Dim KryptonGrid As KryptonExtendedGrid = CType(scrollBar.Parent, KryptonExtendedGrid)
                    If KryptonGrid.ScrollControl IsNot Nothing Then
                        If scrollBar.Visible Then
                            grdForecast.ScrollBars = ScrollBars.None
                            scrollBar.Visible = False
                            scrollBar.Hide()
                            KryptonGrid.ScrollControl.DownButton.Enabled = True
                        Else
                            KryptonGrid.ScrollControl.DownButton.Enabled = False
                        End If
                    End If
                End If
            End If

y53ybaqx

y53ybaqx1#

vb.net,测试过,panel2在panel1内部,panel2的宽度比panel1稍大,足以隐藏滚动条:

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

  Panel1.HorizontalScroll.Visible = False
  Panel1.VerticalScroll.Visible = False

  Panel2.AutoScroll = True
  Panel2.HorizontalScroll.Visible = False
  Panel2.VerticalScroll.Visible = True

End Sub

Private Sub Panel2_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseWheel
  If Panel2.Bounds.Contains(e.Location) Then
    Dim vScrollPosition As Integer = Panel2.VerticalScroll.Value
    vScrollPosition = e.Location.Y
    Panel2.Invalidate()
  End If
End Sub

Private Sub Panel2_MouseEnter(sender As Object, e As EventArgs) Handles Panel2.MouseEnter
   Panel2.Select()
End Sub

End Class

这与2个面板一起工作,它肯定会与一个面板中的任何东西一起工作,在另一个面板中,比如datagridview,你所要做的就是使宽度足够大,以隐藏栏
这是一种简单的方法,因为如果您想真正隐藏它们,则需要覆盖原始控件

5n0oy7gb

5n0oy7gb2#

谢谢大家的支持。我已经自己解决了。我分享的代码,以防任何人需要帮助

Private Sub VScrollBar1_VisibleChanged(ByVal sender As Object, ByVal e As EventArgs)
        Try
            If TypeOf (sender) Is VScrollBar Then
                Dim scrollBar As VScrollBar = CType(sender, VScrollBar)
                If TypeOf (scrollBar.Parent) Is KryptonExtendedGrid Then
                    Dim KryptonGrid As KryptonExtendedGrid = CType(scrollBar.Parent, KryptonExtendedGrid)
                    If KryptonGrid.ScrollControl IsNot Nothing Then
                        If KryptonGrid.ScrollBars = ScrollBars.Vertical  Then
                            KryptonGrid.ScrollBars = ScrollBars.None
                            KryptonGrid.ScrollControl.DownButton.Enabled = True
                        Else
                            KryptonGrid.ScrollControl.DownButton.Enabled = False
                        End If
                    End If
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

相关问题