スクロールバーがデータグリッドビューに表示されているかどうかを確認します

これを試すことができます:

foreach (var scroll in dataGridView1.Controls.OfType<VScrollBar>())
{
   //your checking here
   //specifically... if(scroll.Visible)
}

私はこれが好きです:

//modif is a modifier for the adjustment of the Client size of the DGV window
//getDGVWidth() is a custom method to get needed width of the DataGridView

int modif = 0;
if (DataGridView.Controls.OfType<VScrollBar>().First().Visible)
{
    modif = SystemInformation.VerticalScrollBarWidth;
}
this.ClientSize = new Size(getDGVWidth() + modif, [wantedSizeOfWindow]);

したがって、必要な唯一のブール条件は次のとおりです。

if (DataGridView.Controls.OfType<VScrollBar>().First().Visible)
{
    //want you want to do
}

DataGridViewScrollbars プロパティ ScrollBars を使用して質問できます 列挙 次のように、興味のあるものでマスクします:

if ((dataGridView1.ScrollBars & ScrollBars.Vertical) != ScrollBars.None) ...

ここでは、2 つの 'ScrollBars' は別のものであることに注意してください!