Überprüfen Sie, ob eine Bildlaufleiste in einer Datagridansicht sichtbar ist
Sie können dies ausprobieren:
foreach (var scroll in dataGridView1.Controls.OfType<VScrollBar>())
{
//your checking here
//specifically... if(scroll.Visible)
}
Ich bevorzuge dieses hier:
//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]);
Die einzige boolesche Bedingung, die Sie benötigen, ist also:
if (DataGridView.Controls.OfType<VScrollBar>().First().Visible)
{
//want you want to do
}
Der DataGridView
ist Scrollbars
Eigentum kann mit dem ScrollBars
abgefragt werden Aufzählung indem Sie es wie folgt mit demjenigen maskieren, an dem Sie interessiert sind:
if ((dataGridView1.ScrollBars & ScrollBars.Vertical) != ScrollBars.None) ...
Beachten Sie, dass die beiden 'ScrollBars' hier verschiedene Dinge sind!