[問題] WinForm MouseDown控制單一元件
問題:為什麼在按左右鍵時,在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;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.82.105.152
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1526371811.A.1EA.html
※ 編輯: wtuxxj (111.82.105.152), 05/15/2018 16:33:56
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章