在dataGridView中更改垂直滚动条的宽度

use*_*423 3 c# datagridview scrollbar

我正在为触摸屏开发应用程序.我被要求使滚动条的大小更大,以便用户可以使用它们.到目前为止,我还没有能够对此进行排序.我读到如果你增加MainForm窗口滚动条的宽度,那么dataGridView将继承它.我尝试过一些东西,但到目前为止还没有让它发挥作用.

我尝试的两种最接近的方式是

1)当我构建网格时,我添加以下内容

 foreach (Control ctrl in dataGridView1.Controls)
    if (ctrl.GetType() == typeof(VScrollBar))
       ctrl.Width = 86;
Run Code Online (Sandbox Code Playgroud)

不幸的是,这似乎得到宽度为17但不能用这个86的新值覆盖它.

接下来我把它放到我构建MainForm的地方仍然没有好的垂直滚动条看起来仍然相同.

2)我发现我可以从工具箱中添加滚动条.这里有一点进展,直到我尝试连接到dataGridView.这个我做不到.我有一个事件所以每次移动我都应该能够移动网格.下面注释了我用来确保获得价值的一些项目.

 private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
    {
        //MessageBox.Show(vScrollBar1.Value.ToString());
       // MessageBox.Show(SystemInformation.VerticalScrollBarWidth.ToString());
      //  CalculateVerticalScrollbarWidth() * 4;
    }
Run Code Online (Sandbox Code Playgroud)

所以我想我会问比我更高智商的观众,因为有人可能已经解决了这个问题,并会与我分享答案.

TaW*_*TaW 6

你可以关掉DGV垂直滚动条:

dataGridView1.ScrollBars = ScrollBars.Horizontal;
Run Code Online (Sandbox Code Playgroud)

VerticalScrolllBar而是添加一个Control.确保将其大小保持在snych以及它的Maximum:

vScrollBar1.Maximum = dataGridView1.RowCount;
Run Code Online (Sandbox Code Playgroud)

要同步滚动两个 Scroll事件:

private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
    vScrollBar1.Value = e.NewValue;
}


private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
   dataGridView1.FirstDisplayedScrollingRowIndex = e.NewValue;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述