本帖最后由 lj102800 于 2010-12-10 09:39:48 编辑

解决方案 »

  1.   

    在界面上加一个listbox
    void p_MouseLeave(object sender, EventArgs e)
      {
      ((PictureBox)sender).Left = ((PictureBox)sender).Location.X - 2;
      ((PictureBox)sender).Top = ((PictureBox)sender).Location.Y - 2;
      ((PictureBox)sender).BorderStyle = BorderStyle.None;
    listbox1.Items.Add("p_MouseLeave 可以记录下sender的信息");  }  void p_MouseEnter(object sender, EventArgs e)
      {
      ((PictureBox)sender).Left = ((PictureBox)sender).Location.X + 2;
      ((PictureBox)sender).Top = ((PictureBox)sender).Location.Y+ 2;
      ((PictureBox)sender).BorderStyle = BorderStyle.FixedSingle;
    listbox1.Items.Add("p_MouseEnter 可以记录下sender的信息");
      }
    然后重现这个bug 看看listbox里记录的有没有问题
      

  2.   

    listbox1.Items.Add("p_MouseEnter " + ((PictureBox)sender).Name); 
    上面的格式没调整好
      

  3.   

    是因为移动过快,无法捕捉鼠标事件造成的,还有你的代码可以改改
    PictureBox pic = sender as PictureBox;
    pic.Location = Point.Add(pic.Location, new Size(-2, -2));
    pic.BorderStyle = BorderStyle.None;
      

  4.   

      ((PictureBox)sender).BorderStyle = BorderStyle.None;
    ((PictureBox)sender).Left = ((PictureBox)sender).Location.X - 2;
      ((PictureBox)sender).Top = ((PictureBox)sender).Location.Y - 2;
    换一下位置!!哈哈!
      

  5.   

    我只是简化了你原有的代码至于事件捕捉的问题,是由于控件本身设计的问题,除非你重写控件,或者自己写个带钩子的类去过滤每个pictureBox 的鼠标消息
      

  6.   

    “重写控件,或者自己写个带钩子的类去过滤每个pictureBox 的鼠标消息
    ”帮忙帮到底呗,继续告一下我重写那个方法吧,我都没听说过什么是钩子的类
      

  7.   

    一个弯弯绕的办法,仅供参考,控件不是很多的话能用
    // 只需要 p_MouseEnter 事件
    // 在这个事件中循环检测 pictureBox 控件
    // 可能需要在图片控件容器的 MouseLeave 事件中清除所有图片边框foreach(Control ctrl in this.Controls /*图片容器*/)
    {
        if(ctrl.GetType() == typeof(PictureBox))
            (ctrl as PictureBox).BorderStyle = BorderStyle.None;
    }
    (sender as PictureBox).BorderStyle = BorderStyle.FixedSingle;