google rss rss

          doneykoo [Ouditian]

          DKzone- Ouditian Technology

          Where is Form's Loaded event? [FW]

          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

          posted on 2009-10-16 09:48 DoNeY 閱讀(289) 評論(0)  編輯  收藏 所屬分類: C/C++


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
            doneykoo blogjava
            
          主站蜘蛛池模板: 敦煌市| 德庆县| 宕昌县| 辽源市| 乌拉特中旗| 盐山县| 竹溪县| 鲜城| 汤原县| 平舆县| 蓝山县| 梁河县| 庄浪县| 拉萨市| 瓮安县| 咸阳市| 若尔盖县| 邛崃市| 罗山县| 阿鲁科尔沁旗| 瑞昌市| 红桥区| 越西县| 安吉县| 张掖市| 宜阳县| 酉阳| 昭觉县| 响水县| 通渭县| 溧阳市| 澄迈县| 轮台县| 松原市| 邵武市| 福泉市| 顺义区| 本溪| 涿鹿县| 古交市| 怀安县|