Working Experience - How to handle the destroyed event of UserControl
正文
问题: UserControl 如何在父窗体(程序)关闭时, 释放一些需要手动释放的资源
方法: 使用 Control.FindForm() 获取父窗体, 从而得到父窗体的 Closing/Closed 事件
Form parentForm;
// 可以使用其他方式触发
protected override void OnParentChanged(EventArgs e)
{
base.OnParentChanged(e);
if (parentForm != null)
{
parentForm.Closing -= parentForm_Closing;
}
parentForm = FindForm();
if (parentForm != null)
parentForm.Closing += parentForm_Closing;
}
void parentForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
parentForm.Closing -= parentForm_Closing;
parentForm = null;
//closing code
}
参考
stack overflow - What event signals that a UserControl is being destroyed?
Working Experience - How to handle the destroyed event of UserControl的更多相关文章
- Exception sending context destroyed event to listener instance of class
五月 29, 2019 6:29:39 下午 org.apache.catalina.core.StandardContext listenerStop严重: Exception sending co ...
- 【IOS笔记】Event Delivery: The Responder Chain
Event Delivery: The Responder Chain 事件分发--响应链 When you design your app, it’s likely that you want t ...
- 深入理解jQuery的Event机制
jQuery的Event模块非常强大.其功能远远比原生事件监听器强大许多,对同一个元素的监听只用一个eventListener,内部则是一个强大的观察者,根据匹配事件类型触发相应回调.jQuery不仅 ...
- [Angular 2] Event in deep
This lesson talks about the benefits of using the parens-based (click) syntax so that Angular 2 can ...
- Laravel事件Event
适用场景:记录文章浏览量 php artisan make:event 事件名 示例: php artisan make:event MyEvent Laravel目录\app\Events已经生成M ...
- What is event bubbling and capturing?
What is event bubbling and capturing? 答案1 Event bubbling and capturing are two ways of event propaga ...
- JavaScript Interview Questions: Event Delegation and This
David Posin helps you land that next programming position by understanding important JavaScript fund ...
- window下线程同步之(Event Objects(事件))
Event 方式是最具弹性的同步机制,因为他的状态完全由你去决定,不会像 Mutex 和 Semaphores 的状态会由类似:WaitForSingleObject 一类的函数的调用而改变,所以你可 ...
- Backbone.js 1.0.0源码架构分析(二)——Event
(function(){ //省略前面代码 var Events = Backbone.Events = { // 根据name订阅事件,push到this._events[name] on: fun ...
随机推荐
- 九度OJ 1005:Graduate Admission (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5646 解决:1632 题目描述: It is said that in 2011, there are about 100 graduat ...
- 九度OJ 1024:畅通工程 (最小生成树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3979 解决:1354 题目描述: 省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有 ...
- pm2 的使用
pm2.json 代码如下 [{ "name" : "dingtalk-mobile", "script" : "app.js&q ...
- MV45AOZZ 销售订单增强点
[转自 http://blog.csdn.net/zhongguomao/article/details/6712580]choose the table VBAP or VBAK ( dependi ...
- 改善程序与设计的55个具体做法 day1
博客好久没更新了,就从这本读书笔记开始吧. 条款01: 视C++为一个语言联邦 C++可视为有四个次语言组成的: 1.C语言 2.Object-Oriented C++ (面向对象C++) 3.Tem ...
- eclipse显示adb is down错误,无法真机调试
cmd进入adb目录下,运行adb kill-server 和 adb start-server还是不能正常调试时, 在360的网络连接列表中找到占用端口5037的adb.exe,全部关闭,重启ecl ...
- 【Leetcode-easy】Palindrome Number
思路:除和求余 取得首位和末尾 比较是否相等. public boolean isPalindrome(int x){ if(x<0){ return false; } int div=1; w ...
- Linux-3.14.12内存管理笔记【kmalloc与kfree实现】【转】
本文转载自:http://blog.chinaunix.net/uid-26859697-id-5573776.html kmalloc()是基于slab/slob/slub分配分配算法上实现的,不少 ...
- LightOJ 1132 Summing up Powers:矩阵快速幂 + 二项式定理
题目链接:http://lightoj.com/volume_showproblem.php?problem=1132 题意: 给定n.k,求(1K + 2K + 3K + ... + NK) % 2 ...
- lucene内置的评分函数
For multiterm queries, Lucene takes the Boolean model, TF/IDF, and the vector space model and combin ...