首页 新闻 会员 周边 捐助

关于窗体改变大小的鼠标弹起事件问题

0
悬赏园豆:20 [已解决问题] 解决于 2024-06-17 12:16

上次编写了窗体改变大小的博文,里面用的API函数,模拟正常窗体的边框改变大小的操作。但是有一个问题,就是当按下鼠标改天窗体大小后,弹起事件没执行啊,请问该如何解决?

https://www.cnblogs.com/lzhdim/p/18114056

 

弹起事件绑定:

this.PanelTopCenter.MouseUp += (s, e) => { if (e.Button == MouseButtons.Left) SaveNote(); };
this.PanelTopLeftCorner.MouseUp += (s, e) => { if (e.Button == MouseButtons.Left) SaveNote(); };
this.PanelTopRightCorner.MouseUp += (s, e) => { if (e.Button == MouseButtons.Left) SaveNote(); };

this.PanelBorderLeft.MouseUp += (s, e) => { if (e.Button == MouseButtons.Left) SaveNote(); };
this.PanelBoderRight.MouseUp += (s, e) => { if (e.Button == MouseButtons.Left) SaveNote(); };

this.PanelBottomCenter.MouseUp += (s, e) => { if (e.Button == MouseButtons.Left) SaveNote(); };
this.PanelBottomLeftCorner.MouseUp += (s, e) => { if (e.Button == MouseButtons.Left) SaveNote(); };
this.PanelBottomRightCorner.MouseUp += (s, e) => { if (e.Button == MouseButtons.Left) SaveNote(); };
C#
lzhdim的主页 lzhdim | 小虾三级 | 园豆:650
提问于:2024-06-15 19:35
< >
分享
最佳答案
0

按下鼠标改天窗体大小时,激活窗体,释放鼠标激发窗体MouseUp,而非Panel.MouseUp

收获园豆:20
泡沫游走 | 菜鸟二级 |园豆:273 | 2024-06-15 20:47

1、按下鼠标的时候窗体就是激活状态吧???

2、鼠标在Panel上的啊,应该是Panel.MouseUp,你写代码测试过吗?

 

请给出解决的代码,谢谢。。。

lzhdim | 园豆:650 (小虾三级) | 2024-06-15 21:31

@lzhdim: 你把源代码放到csdn中,博客代码是图片,还要直接给解决代码,你是咋想的?

泡沫游走 | 园豆:273 (菜鸟二级) | 2024-06-15 21:56

@泡沫游走: 最终的解决方案代码啊。。。CSDN那个是能够下载的,不需要积分。。就是根据你说的试了下没效果所以才找你要最终代码啊。

lzhdim | 园豆:650 (小虾三级) | 2024-06-15 22:01
其他回答(1)
0

直接在调用API函数后面加上MouseUp事件的代码即可,这样当拖放窗体大小释放鼠标后会进行操作,见下面代码:

执行的代码为:if (_CanResize) DecorationMouseDown(e, HitTestValues.HTTOP); SaveNote(); 。当释放鼠标后会执行SaveNote();这个操作。

#region 绑定改变窗体大小的Panel控件的鼠标按下事件

this.PanelTopCenter.MouseDown += (s, e) => { if (_CanResize) DecorationMouseDown(e, HitTestValues.HTTOP); SaveNote(); };
this.PanelTopLeftCorner.MouseDown += (s, e) => { if (_CanResize) DecorationMouseDown(e, HitTestValues.HTTOPLEFT); SaveNote(); };
this.PanelTopRightCorner.MouseDown += (s, e) => { if (_CanResize) DecorationMouseDown(e, HitTestValues.HTTOPRIGHT); SaveNote(); };

this.PanelBorderLeft.MouseDown += (s, e) => { if (_CanResize) DecorationMouseDown(e, HitTestValues.HTLEFT); SaveNote(); };
this.PanelBoderRight.MouseDown += (s, e) => { if (_CanResize) DecorationMouseDown(e, HitTestValues.HTRIGHT); SaveNote(); };

this.PanelBottomCenter.MouseDown += (s, e) => { if (_CanResize) DecorationMouseDown(e, HitTestValues.HTBOTTOM); SaveNote(); };
this.PanelBottomLeftCorner.MouseDown += (s, e) => { if (_CanResize) DecorationMouseDown(e, HitTestValues.HTBOTTOMLEFT); SaveNote(); };
this.PanelBottomRightCorner.MouseDown += (s, e) => { if (_CanResize) DecorationMouseDown(e, HitTestValues.HTBOTTOMRIGHT); SaveNote(); };

#endregion 绑定改变窗体大小的Panel控件的鼠标按下事件
lzhdim | 园豆:650 (小虾三级) | 2024-06-16 23:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册