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

推荐订阅源

I
InfoQ
C
CERT Recently Published Vulnerability Notes
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
P
Privacy & Cybersecurity Law Blog
Simon Willison's Weblog
Simon Willison's Weblog
Jina AI
Jina AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
博客园_首页
F
Fortinet All Blogs
博客园 - Franky
Latest news
Latest news
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
D
Docker
Project Zero
Project Zero
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
Cisco Talos Blog
Cisco Talos Blog
Y
Y Combinator Blog
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
H
Help Net Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
PCI Perspectives
PCI Perspectives
Cloudbric
Cloudbric
V
Visual Studio Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理

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