C# Winform 自适应大小 按上下键切换控件焦点
按上下键切换控件焦点(只对textbox有效)
privatevoid 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;
}
}
}
}
自适应大小
privatevoid Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState.ToString() =="Maximized")
{
this.dataGridView1.Width =this.Size.Width-35;
}
elseif (this.WindowState.ToString() =="Normal")
{
this.dataGridView1.Width =this.Size.Width-35;
}
else
{
this.dataGridView1.Width =this.Size.Width-35;
}
}

浙公网安备 33010602011771号