更改dataGridView中垂直滚动条的宽度 [英] Changing width of vertical scroll bar in dataGridView

查看:316
本文介绍了更改dataGridView中垂直滚动条的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于触摸屏的应用程序.我被要求增大滚动条的大小,以便用户可以使用它们.到目前为止,我还无法进行排序.我读到,如果您增加MainForm窗口滚动条的宽度,则dataGridView将继承它.我已经尝试了一些方法,但到目前为止仍无法使其正常工作.

I am developing an App for a touchscreen. I have been asked to make the size of the scroll bars bigger so the users can use them. So far I have not been able to get this sorted. I read that if you increase the width of MainForm window scroll bar then dataGridView will inherit it. I have tried a few things but so far have failed to get it to work.

我尝试过的两种最接近的方法是

The two closest ways I tried are

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

1) When I build the grid I add the following

 foreach (Control ctrl in dataGridView1.Controls)
    if (ctrl.GetType() == typeof(VScrollBar))
       ctrl.Width = 86;

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

Unfortunately this seems to get the Width of 17 but not able to override it with this new value of 86.

接下来,我将其放入构建MainForm的位置,垂直滚动条仍然看起来不一样.

Next I put this into where I build the MainForm still no good the vertical scroll bar still looks the same.

2)我发现我可以从工具箱中添加滚动条.在我尝试连接到dataGridView之前,这里已有一些进展.我做不到我有一个事件,因此每次移动时,我都应该能够移动网格.以下注释掉了我用来确保获得价值的一些物品.

2) I find that I could add a scroll bar from the tool box. A bit of progress here until I try to connect to dataGridView. This I cannot do. I have an event so everytime it is moved I should be able to move the grid. Below commented out are a few items that I use to make sure I am getting a value.

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

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

So I thought I would ask the audience of higher intelligence than me as someone may have solved this and will share the answer with me.

推荐答案

您可以关闭DGV的垂直滚动条:

You can turn off the DGV's vertical scroll bar:

dataGridView1.ScrollBars = ScrollBars.Horizontal;

并添加一个VerticalScrolllBar控件.确保将其大小保留在snych中,并保留其Maximum:

And add a VerticalScrolllBar Control instead. Make sure to keep its size in snych and also its Maximum:

vScrollBar1.Maximum = dataGridView1.RowCount;

要滚动同步代码两者 Scroll事件:

To scroll in synch code both Scroll events:

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


private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
   dataGridView1.FirstDisplayedScrollingRowIndex = e.NewValue;
}

这篇关于更改dataGridView中垂直滚动条的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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