C# Winform 自适应大小 按上下键切换控件焦点

按上下键切换控件焦点(只对textbox有效)

private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 40 || e.KeyValue == 13)
{
SendKeys.Send("{TAB}");
}
if (e.KeyValue == 38)
{
int index= this.textBox2.TabIndex;
for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i].TabIndex == (index - 1))
{
this.Controls[i].Focus();
break;
}
}
}
}

自适应大小

private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState.ToString() == "Maximized")
{
this.dataGridView1.Width = this.Size.Width-35;
}
else if (this.WindowState.ToString() == "Normal")
{
this.dataGridView1.Width = this.Size.Width-35;
}
else
{
this.dataGridView1.Width = this.Size.Width-35;
}
}