c# – 在拖放过程中重绘
发布时间:2020-12-15 08:12:01 所属栏目:百科 来源:网络整理
导读:我想在DragEnter和DragLeave事件期间触发拖动目标控件以重绘自身(通过无效或刷新).代码看起来像: protected override void OnDragEnter (DragEventArgs drgargs){ //-- Set a property that affects drawing of control,then redraw this.MyProperty = true
我想在DragEnter和DragLeave事件期间触发拖动目标控件以重绘自身(通过无效或刷新).代码看起来像:
protected override void OnDragEnter (DragEventArgs drgargs) { //-- Set a property that affects drawing of control,then redraw this.MyProperty = true; this.Refresh(); //-- Does nothing??? } protected override void OnDragLeave (EventArgs e) { //-- Set a property that affects drawing of control,then redraw this.MyProperty = false; this.Refresh(); //-- Does nothing??? } 它实际上不会重绘控件,这些事件中的Refresh()不会调用OnPaint方法.有没有办法做到这一点?我不能在这里理解一些事情. 更新:jasonh提供的答案实际上并不起作用.使用Invalidate()或Invalidate(rect)时,控件实际上不会更新.这是在拖放操作期间进行的调用.还有其他想法吗?你可以在拖放过程中触发重绘控件吗?谢谢! 更新2:我创建了一个示例项目,但无法使其无效.叹了口气……我终于将它追溯到导致问题的OnPaint中的一些代码.所以,事实证明我更多的是不了解调试器是如何工作的(它从未在OnPaint中遇到断点……仍然不知道为什么). Invalidate(),Refresh()都有效. JasonH得到了答案,因为它最终是正确的,并且还展示了如何使控件的一部分无效……我不知道这一点. 感谢你的帮助! 解决方法
调用this.Invalidate()以使表单/控件重绘自身.如果您知道特定区域,则调用其中一个重载方法以指定要使其无效的内容.例如:
Rectangle toInvalidate = new Rectangle(drgargs.X - 50,drgargs.Y - 50,50,50); this.Invalidate(toInvalidate); 这将使拖动目标区域周围50个像素的区域无效. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |