void textBox2_KeyDown(object sender,KeyEventArgs e)
{
Control ctr= (Control)sender;
switch (e.KeyData)
{
case Keys.Right:
if (ctr.Right == 0)
{ MessageBox.Show("已到顶"); }
else
{ ctr.Location = new Point(ctr.Location.X + 5, ctr.Location.Y + 5); }
break;
case Keys.Up:
if (ctr.Top == 0)
{ MessageBox.Show("已到顶"); }
else
{ //ctr.Top -= 5;
ctr.Location = new Point(ctr.Location.X, ctr.Location.Y - 5);
}
break;
case Keys.Down:
if (ctr.Bottom == 0)
{ MessageBox.Show("已到顶"); }
else
{ //ctr.Top += 5;
ctr.Location = new Point(ctr.Location.X, ctr.Location.Y + 5);
}
break;
case Keys.Left:
if (ctr.Left == 0)
{ MessageBox.Show("已到顶"); }
else
{ //ctr.Left -= 5;
ctr.Location = new Point(ctr.Location.X - 5, ctr.Location.Y);
}
break;
}
if (e.KeyCode == Keys.Right)
{
if (ctr.Top == 0)
{
MessageBox.Show("已到顶");
}
else
{
ctr.Top -= 5;
}
}
}