[问题] WinForm MouseDown控制单一元件

楼主: wtuxxj (尋找Miss Right)   2018-05-15 16:10:07
问题:为什么在按左右键时,在form上的pbBar及hsSpeed
都会跟着动,现在初步的解决方法是
e.SuppressKeyPress = true;
如此hsSpeed就不会跟着动了
WinForm上元件:
PictureBox1 = pbBall
PictureBox2 = pbBar
HScrollBar = hsSpeed
Function:
在WinForm上加了KeyDown
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
int moveX = pbBar.Location.X;
int moveY = pbBar.Location.Y;
if (e.KeyCode == Keys.Right)
{
pBarMove = new Point(this.pbBar.Left + 10, this.pbBar.Top);
pbBar.Location = pBarMove;
}
if (e.KeyCode == Keys.Left)
{
pBarMove = new Point(this.pbBar.Left - 10, this.pbBar.Top);
pbBar.Location = pBarMove;
}
// 防止hsSpeed动作
e.SuppressKeyPress = true;
}

Links booklink

Contact Us: admin [ a t ] ucptt.com