日期:2014-05-17  浏览次数:20891 次

c#winform picturebox控件中label实现点击
实现功能:在picturebox中放入两个label,一个用于浏览图片,另一个删除图片,当鼠标放在picturebox控件时,两个label都显示,当鼠标离开picturebox控件时,两个label都不显示,为什么点击两个label控件时mousedown事件不会触发
 private void contact_pic_MouseLeave(object sender, EventArgs e)
  {

  lb_liulan.Visible = false;
  label5.Visible = false;
  }
 private void contact_pic_MouseEnter(object sender, EventArgs e)
  {
  lb_liulan.Visible = true;
  label5.Visible = true;
  }
 private void lb_liulan_MouseDown(object sender, MouseEventArgs e)
  {
  lb_liulan.Enabled = true;
  opd_pic.ShowDialog();
  }
  private void label5_MouseDown(object sender, MouseEventArgs e)
  {
  contact_pic.Image = null;
  contact_pic.Tag = "";
  }

------解决方案--------------------
用一个System.Timers.Timer类去执行label的隐藏,当鼠标移出picturebox的时候触发timer事件,timer时间间隔你自己设定,里面判断timer里面判断label是不是显示的,是显示的就隐藏!

timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);

void timer_Elapsed(object sender, ElapsedEventArgs e)
{
lb_liulan.Visible = false;
label5.Visible = false;
}
------解决方案--------------------
不要使用定时器,定时器使用不好会带来更麻烦的问题。
你的想法其实很简单,实现也不难:
1、鼠标在Pic上,Label显示
2、鼠标不在Pic上,但是在Label上,Label显示
3、鼠标不在Pic上,也不在Label上,Label隐藏