winform 中mouseEnter和mouseLeave事件 本帖最后由 lj102800 于 2010-12-10 09:39:48 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在界面上加一个listboxvoid 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里记录的有没有问题 listbox1.Items.Add("p_MouseEnter " + ((PictureBox)sender).Name); 上面的格式没调整好 是因为移动过快,无法捕捉鼠标事件造成的,还有你的代码可以改改PictureBox pic = sender as PictureBox;pic.Location = Point.Add(pic.Location, new Size(-2, -2));pic.BorderStyle = BorderStyle.None; ((PictureBox)sender).BorderStyle = BorderStyle.None;((PictureBox)sender).Left = ((PictureBox)sender).Location.X - 2; ((PictureBox)sender).Top = ((PictureBox)sender).Location.Y - 2;换一下位置!!哈哈! 我只是简化了你原有的代码至于事件捕捉的问题,是由于控件本身设计的问题,除非你重写控件,或者自己写个带钩子的类去过滤每个pictureBox 的鼠标消息 “重写控件,或者自己写个带钩子的类去过滤每个pictureBox 的鼠标消息”帮忙帮到底呗,继续告一下我重写那个方法吧,我都没听说过什么是钩子的类 一个弯弯绕的办法,仅供参考,控件不是很多的话能用// 只需要 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; 为什么用VS制作的安装文件 安装后生成的图标 属性中目标项不能用 c#只能以流的方式读取或写入文件吗? 软件运行速度问题 获取xml节点名称动态赋给类的属性 winform问题,datagridview 执行onpaint事件后。。。 combobox和textBox的组合问题 有谁在c#下用过SMEIDll.dll? 自定义控件问题 关于数据库存图的问题,各位老大帮我看看啊。 一个C#的问题 有哪位用过DevExpress.XtraScheduler.SchedulerControl控件的 请问怎样把一个数值保存到TXT文本里边去
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里记录的有没有问题
上面的格式没调整好
PictureBox pic = sender as PictureBox;
pic.Location = Point.Add(pic.Location, new Size(-2, -2));
pic.BorderStyle = BorderStyle.None;
((PictureBox)sender).Left = ((PictureBox)sender).Location.X - 2;
((PictureBox)sender).Top = ((PictureBox)sender).Location.Y - 2;
换一下位置!!哈哈!
”帮忙帮到底呗,继续告一下我重写那个方法吧,我都没听说过什么是钩子的类
// 只需要 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;