锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美日韩五码,中文字幕日韩欧美一区二区三区,一二三在线视频社区http://www.aygfsteel.com/doneykoo/category/37896.htmlDKzone- Ouditian Technologyzh-cnFri, 16 Oct 2009 10:35:45 GMTFri, 16 Oct 2009 10:35:45 GMT60Where is Form's Loaded event? [FW]http://www.aygfsteel.com/doneykoo/archive/2009/10/16/298505.htmlDoNeYDoNeYFri, 16 Oct 2009 01:48:00 GMThttp://www.aygfsteel.com/doneykoo/archive/2009/10/16/298505.htmlhttp://www.aygfsteel.com/doneykoo/comments/298505.htmlhttp://www.aygfsteel.com/doneykoo/archive/2009/10/16/298505.html#Feedback0http://www.aygfsteel.com/doneykoo/comments/commentRss/298505.htmlhttp://www.aygfsteel.com/doneykoo/services/trackbacks/298505.html Where is Form's Loaded event?

[FW]http://weblogs.asp.net/kennykerr/archive/2004/11/26/where-is-form-s-loaded-event.aspx

Wow, it’s been a while since I last posted something here. We’ve recently moved to BC so I’ve been pretty distracted. I hope to be able to post more regularly in the coming weeks.

This is a bit off-topic for me but here goes.

Recently I needed to run some code right after a form is displayed for the first time. The Form.Load event is handy for performing various tasks when a form is loading but before it is displayed for the first time. Unfortunately there is no corresponding Form.Loaded event to notify the application that the form has actually loaded and is visible.

Fortunately it’s quite easy to pull it off without resorting to the WaitForInputIdle function. All you need to do is override Form’s OnLoad method and add an event handler for the Application.Idle event. Since we only want to be notified a single time that the form is loaded, we immediately remove the delegate in the event handler. You can of course register the event handler earlier in the form or application’s lifetime but I prefer to keep delegates registered for as short a period as possible.

Here’s a simple example:


 1 protected override void OnLoad(EventArgs args)
 2 {
 3     base.OnLoad(args);
 4 
 5     Application.Idle += new EventHandler(OnLoaded);
 6 }
 7 
 8 private void OnLoaded(object sender,
 9                       EventArgs args)
10 {
11     Application.Idle -= new EventHandler(OnLoaded);
12 
13     // TODO: add relevant code here
14 }
15 

This might be useful, for example, if you need to prompt the user (the horror!) for something but would prefer the dialog box to appear in the context of your application’s main window.


© 2004 Kenny Kerr



DoNeY 2009-10-16 09:48 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 平顶山市| 双柏县| 称多县| 兴和县| 西吉县| 紫阳县| 瓦房店市| 绿春县| 偃师市| 象州县| 措美县| 固始县| 天峻县| 乐亭县| 保定市| 扬中市| 舒城县| 安图县| 尚义县| 安新县| 牡丹江市| 隆化县| 措美县| 赣州市| 阜新| 云浮市| 乡宁县| 西昌市| 平顺县| 大理市| 涿鹿县| 嘉禾县| 黎城县| 临邑县| 加查县| 焉耆| 洪江市| 三原县| 太原市| 伊春市| 浦江县|