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

推荐订阅源

F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
T
Tenable Blog
Hugging Face - Blog
Hugging Face - Blog
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
P
Proofpoint News Feed
H
Hacker News: Front Page
P
Privacy & Cybersecurity Law Blog
月光博客
月光博客
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
博客园_首页
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
Forbes - Security
Forbes - Security
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Hacker News - Newest:
Hacker News - Newest: "LLM"
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
O
OpenAI News
G
Google Developers Blog
Martin Fowler
Martin Fowler
罗磊的独立博客
S
SegmentFault 最新的问题
T
Tor Project blog
量子位

博客园 - 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