惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
T
The Blog of Author Tim Ferriss
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
爱范儿
爱范儿
GbyAI
GbyAI
H
Help Net Security
I
InfoQ
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
A
Arctic Wolf
Know Your Adversary
Know Your Adversary
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tor Project blog
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
WordPress大学
WordPress大学
V
Visual Studio Blog
博客园_首页
G
GRAHAM CLULEY
K
Kaspersky official blog
T
Tailwind CSS Blog
T
Threat Research - Cisco Blogs
博客园 - Franky
D
Docker
Security Latest
Security Latest
I
Intezer
有赞技术团队
有赞技术团队
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 【当耐特】
B
Blog RSS Feed
T
The Exploit Database - CXSecurity.com
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - answer

SQL查询重复记录 如何使用两台 NETGEAR 无线路由器进行无线中继(WDS) [转]取当前日期是在一年中的第几周 给List排序( list sort) [转]检查本地DNS服务器是否正常工作及解决方法 SQLITE入门至精通 [转]WM手机,关于如何让手机一直运行下去,而不进入待机 [转]string表达式运算 [转]HTC G11 ROOT获取权限教程 [转]WebForm 与 winform 路径获取 [转]win7 系统装SQLServer2000 成功。 Mobile Development: Disable Windows Mobile 6.5 Start and Close Button [转]Windows Mobile: Hide StartButton in WinMo 6.5.x Windows CE 电源管理(转贴) [转]分享8个超棒的免费高质量图标搜索引擎 [转]Win7系统下VS2005_2008不识别WinCE5 SDK [转]windows 7 下ASP.net 本地配置 ( IIS 7) [转]SQLite存取二进制数据 [转]SelectObject() 装载字体 VC EVC
[转]写在UserControl销毁之时
answer · 2012-10-26 · via 博客园 - answer

近来使用C#编程,需要在主窗体关闭之前将现在的地图中的图层的某一状态置为初始状态,而此方法又需要写在UserControl自定义控件类之中。

但是在继承UserControl类的事件里,却找不到合适的事件对此方法进行触发。UserControl并没有定义FormClosing事件。

想到两种办法:

1. 重载自定义控件类的Dispose()方法;(网上刚看到一种解决办法,说是重载IDisposable.Dispose方法,Dispose(True);GC.SuppressFinalize(this);还没来得及试过。)

2. this.ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing);

this.ParentForm属性直接返回父窗体;而this.Parent属性返回最直接的父Control,想要通过此属性得到父窗体还需要遍历嵌套的控件层次。

但是这两种方法执行的时候,都会偶尔使得程序弹出这样的错误: “将COM对象与其基础RCW分开后不能再使用该对象”。

最后,突发奇想,想出来一个变通的解决办法:

将此方法在程序刚加载运行的时候执行,比如注册到主窗体的Load事件中,这样就不会出现异常了。

不过这种方法使用情况有很大局限性,针对独立的程序系统使用时较为适宜。

来自: http://blog.csdn.net/freewaywalker/article/details/7757517