C# mousedown無法呼叫
int i, j;
public Form1()
{
InitializeComponent();
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.Image = Image.FromFile("C:\\Documents and Settings\\adam\\桌面\\C#\\end.jpg");
pictureBox1.Location = new Point(500, 12);
pictureBox1.BringToFront(); //移到最上面
pictureBox2.Image = Image.FromFile("C:\\Documents and Settings\\adam\\桌面\\C#\\one.jpg");
pictureBox2.Location = new Point(x, y);
}
private void timer1_Tick(object sender, EventArgs e)
{ }
private void pictureBox2_Click(object sender, EventArgs e)
{
v = numericUpDown1.Value;
timer1.Start();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{ }
private void label1_Click(object sender, EventArgs e)
{ }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.Cursor = Cursors.Hand;
i = e.X;
j = e.Y;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
pictureBox1.Left = pictureBox1.Left + e.X-i;
pictureBox1.Top = pictureBox1.Top + e.Y-j;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
pictureBox1.Left = pictureBox1.Left + e.X - i;
pictureBox1.Top = pictureBox1.Top + e.Y - j;
}
private void pictureBox1_Click(object sender, EventArgs e)
{ }
這是我部分程式碼 , 我有上網查有關mousemove等相關資料
但是當我執行 , 卻沒有辦法移動pictureBox1
即使我在pictureBox1_MouseDown 加入
if (e.Button == MouseButtons.Left)
{MessageBox.Show("表單上按下滑鼠的左鍵";)}
也沒有動作~~不知道是發生什麼問題~謝謝幫忙@@a
1 Answer
- Anonymous7 years agoFavorite Answer
請先用debug模式,在MouseDown, mousemove的function裡加中斷點,然後執行、點按pictureBox後看有沒有進去
再來你的MouseDown, mousemove是怎麼加入的?
在點選物件時,右邊會有個「屬性」頁,裡面有個閃電圖案,在裡面找到你要的,然後點兩下加進去,這樣才是正確的做法。
如果只是照著把程式打進去的話,不會動是正常的。