最近做C/S.有个问题想请教各位有经验的。
一个大的picturebox1里面添加一个小的子控件picturebox2 。当picturebox1的mouse_enter时显示picturebox2,mouse_leave的时候picturebox2不可见。
问题是如何当picturebox1进入时让picturebox2获得焦点并且可以执行点击事件呢?
小女子第一次发帖,希望能有积极的回应!!谢谢大家啦!

解决方案 »

  1.   

    如果希望picturebox2可以执行点击事件,请调用:
    pictureBox2.BringToFront();
    使之处于最上方,不用时,再调用:
    pictureBox2.SendToBack();
      

  2.   

    picturebox有一个属性 Visible  设置鼠标进入时visible=true 离开时visible=false
    不就可以了吗? 
      

  3.   

    鼠标进入时显示PictureBox2和移出时隐藏PictureBox2是可以实现,问题是让PictureBox2获得焦点并能触发点击的事件 ,如题
      

  4.   

    用我说的方法应该可以,不妨一试。
    如果还不行,加我好友好了,或者发邮件到:
    [email protected]
    我也在做类似的界面。
      

  5.   

    有一个visibleChang事件 就是说在这个事件里面 判断if  visible==true  就写做你点击之后要做的事件。。清楚不?
      

  6.   

    也不行诶…… 因为pictruebox2无法获得焦点,当鼠标移到pictruebox2上时会先调用pictruebox1的mouse_leave事件,图片就显示不了了,还怎么获得焦点呢?
    况且我是现在可见的状态下和点击的动作中执行pictruebox2的事件。
      

  7.   


    private void pictureBox1_MouseEnter(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = true;
                pictureBox2_Click(sender, e);
            }        private void pictureBox2_Click(object sender, EventArgs e)
            {
                if (this.pictureBox2.Visible==false)
                {
                    this.pictureBox1.Focus();
                }
             
               
            }        private void pictureBox1_MouseLeave(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = false;
            }在BOX2的CLICK事件里加断点,自己看看,是不是要这样的效果
      

  8.   

    好吧,你尝试动态注册和移除
    pictureBox1_MouseLeave事件
    这样就不会出现冲突了
      

  9.   

       private void pictureBox1_MouseEnter(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = true;
            }        private void pictureBox2_MouseEnter(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = true;
            }        private void pictureBox1_MouseLeave(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = false;
            }
      

  10.   

    很明显第二个BOX的点击事件也出发了啊
      

  11.   

    为什么美女就这么多回帖
       我那一个人也没
     都过去看看http://topic.csdn.net/u/20100416/10/db615811-504d-4ff7-a1fe-6cee172d9973.html?82211
      

  12.   

    当pictureBox2显示时根本无法获得焦点,总是pictureBox1的mouse_enter和mouse_leave循环。
    补充一点 。pictureBox1和pictureBox2都是动态添加的。
    难道这个问题就没有人能解决么? 是不是我的想法太勉强了??!
      

  13.   


     private void pictureBox1_MouseEnter(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = true;
                pictureBox2_Click(sender, e);
            }        private void pictureBox2_Click(object sender, EventArgs e)
            {
                if (this.pictureBox2.Visible==false)
                {
                    this.pictureBox1.Focus();
                }            this.pictureBox1.MouseLeave += new EventHandler(pictureBox1_MouseLeave);
            }        private void pictureBox1_MouseLeave(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = false;
                this.pictureBox1.MouseLeave -= new EventHandler(pictureBox1_MouseLeave);
            }这样呢
      

  14.   


    这是我的代码 pb2代表picturebox2,pb代表picturebox1.就是点击事件进不去?还请帮忙找出问题所在。 pb2.MouseEnter += new EventHandler(pb2_MouseEnter);
     pb2.Click += new EventHandler(pbView_Click); pb.MouseEnter += new EventHandler(pb_MouseEnter);
     pb.MouseLeave += new EventHandler(pb_MouseLeave); private void pbView_Click(object sender, EventArgs e)
     {
        MessageBox.Show("click");
     }
     private void pb_MouseEnter(object sender, EventArgs e)
     {
         PictureBox pbView = ((PictureBox)sender);
         if (pbView.Controls.Count == 0) return;
         pbView.Controls[0].Visible = true;          
     }
     private void pb_MouseLeave(object sender, EventArgs e)
     {
         PictureBox pbView = ((PictureBox)sender);
         if (pbView.Controls.Count == 0) return;
         pbView.Controls[0].Visible = false;          
     }
     private void pb2_MouseEnter(object sender, EventArgs e)
     {
          PictureBox pbView = ((PictureBox)sender);
          pbView.Visible = true;     
     }
      

  15.   

    private void pb_MouseEnter(object sender, EventArgs e)
     {
      PictureBox pbView = ((PictureBox)sender);
      if (pbView.Controls.Count == 0) return;
      pbView.Controls[0].Visible = true;   
     }这段代码有些问题。 你可以把一个picturebox嵌入到另一个pciturebox里面?
      

  16.   

    插问一句你想要什么效果。直接改IMAGE属性不行么?还有一点奇怪“当picturebox1的mouse_enter时显示picturebox2,mouse_leave的时候picturebox2不可见。”我直接判断picturebox2的mouse_leave,再隐藏picturebox2不行么?为什么全部要放到picturebox1去?
      

  17.   

    再退一步说我判断鼠标位置来控制显示也可以的啊,用Location和Size两属性很容易算出作用范围。
      

  18.   

    写个类picture类继承picture在里面写一些东西。没多复杂。
      

  19.   

    pbView是什么?你不是要执行pd2的点击事件么
      

  20.   

    设置一个标记flag 初始值为FALSE ,若flag为flase,在picbox1的enter事件之后,设置picbox1可见并且获得焦点,设置flag为TRUE。bicbox1的level事件只有在flag为FALSE时才执行picbox2的点击操作。
      

  21.   

    图片看不到……你不要把pb2弄成pb的子控件
    你试一下
      

  22.   

    我知道你是什么问题了 private void pb2_MouseEnter(object sender, EventArgs e)
     {
      PictureBox pbView = ((PictureBox)sender);
      pbView.Visible = true;   
     }
    //改成
    private void pb2_MouseEnter(object sender, EventArgs e)
     {
    pb.MouseLeave += new EventHandler(pb_MouseLeave);
      PictureBox pbView = ((PictureBox)sender);
      pbView.Visible = true;   
     }当然 前边就不要在注册pb鼠标离开事件了
      

  23.   

    要实现你想要的效果需要动态的将事件注册跟取消,而且注册取消的顺序与你的逻辑相关!以下代码仅供参考:private void Form1_Load(object sender, EventArgs e)
            {
                this.pb.MouseEnter += new EventHandler(pb_MouseEnter);
                this.pb2.Click += new EventHandler(pb2_Click);
                
            }        void pb_MouseEnter(object sender, EventArgs e)
            {
                pb2.Visible = true;
                
                this.pb.MouseEnter -= pb_MouseEnter;
            }        void pb_MouseLeave(object sender, EventArgs e)
            {
                this.pb.MouseEnter += pb_MouseEnter;
                pb2.Visible = false;
                this.pb.MouseLeave -= pb_MouseLeave;
                
            }        void pb2_Click(object sender, EventArgs e)
            {
                MessageBox.Show("ae");
                this.pb.MouseLeave += pb_MouseLeave;        }
      

  24.   

    我提个意见:
    在方法  private void pictureBox1_MouseLeave(object sender, EventArgs e)
      {
          .................
      }里加个判断,判断鼠标的当前位置是不是还在pictureBox1的显示范围内,如果是就一直让pictureBox2显示,反之就让pictureBox2隐藏,这样当鼠标从pictureBox1进入pictureBox2时,pictureBox2就不会失去焦点
      

  25.   


    确实可以点击picturebox2的点击事件 但是pictbox1的移入移出又有问题了……
      

  26.   

                Point currentMousePoint = Form.MousePosition;
                // Determines if the mouse points to a ListViewItem.
                Point clientMousePoint = this.PointToClient(currentMousePoint);
                if (this.pictureBox1.Bounds.Contains(clientMousePoint))
                {
                    this.pictureBox2.Visible = true;
                }
                else
                this.pictureBox2.Visible = false;
      

  27.   

    private void pictureBox1_MouseEnter(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = true;
                pictureBox2_Click(sender, e);
            }        private void pictureBox2_Click(object sender, EventArgs e)
            {
                if (this.pictureBox2.Visible==false)
                {
                    this.pictureBox1.Focus();
                }
             
               
            }        private void pictureBox1_MouseLeave(object sender, EventArgs e)
            {
                this.pictureBox2.Visible = false;
            }
    看看实在身事件里面额啊