上次编写了窗体改变大小的博文,里面用的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(); };
按下鼠标改天窗体大小时,激活窗体,释放鼠标激发窗体MouseUp,而非Panel.MouseUp
1、按下鼠标的时候窗体就是激活状态吧???
2、鼠标在Panel上的啊,应该是Panel.MouseUp,你写代码测试过吗?
请给出解决的代码,谢谢。。。
@lzhdim: 你把源代码放到csdn中,博客代码是图片,还要直接给解决代码,你是咋想的?
@泡沫游走: 最终的解决方案代码啊。。。CSDN那个是能够下载的,不需要积分。。就是根据你说的试了下没效果所以才找你要最终代码啊。
直接在调用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控件的鼠标按下事件