Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to turn off executing Load event at design time feature?

How to turn off executing Load event at design time feature?

Scheduled Pinned Locked Moved C#
questionhtmlvisual-studiocomdesign
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T t800t8

    I try to write a class that extends Form like that: public partial class BaseForm : Form { public BaseForm() { InitializeComponent(); } private void BaseForm_Load(object sender, System.EventArgs e) { MessageBox.Show("Hello, World!"); } } And then I write a class that extends class BaseForm public partial class MyForm : BaseForm { public MyForm() { InitializeComponent(); } } I rebuild project and open MyForm to design, it suddenly appears "Hello, World!" message box. I think it is a stupid feature in VS 2005 (I didn't check it in VS 2002, 2003 yet). How can I turn off this feature? http://t800t8.blogspot.com/2006/02/thc-thi-s-kin-load-khi-ang-design-form.html I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing -- modified at 19:58 Monday 20th February, 2006

    M Offline
    M Offline
    Marc 0
    wrote on last edited by
    #2

    private void BaseForm_Load(object sender, System.EventArgs e){
    protected override void OnLoad(System.EventArgs e){
    if (!base.DesignMode[^]){
    MessageBox.Show("Hello, World!");
    }
    }


    "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


    || Fold With Us! || Pensieve || VG.Net || -- modified at 20:20 Monday 20th February, 2006

    T 1 Reply Last reply
    0
    • M Marc 0

      private void BaseForm_Load(object sender, System.EventArgs e){
      protected override void OnLoad(System.EventArgs e){
      if (!base.DesignMode[^]){
      MessageBox.Show("Hello, World!");
      }
      }


      "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


      || Fold With Us! || Pensieve || VG.Net || -- modified at 20:20 Monday 20th February, 2006

      T Offline
      T Offline
      t800t8
      wrote on last edited by
      #3

      This code, it works. Thanks! :-) private void BaseForm_Load(object sender, System.EventArgs e){ if (!base.DesignMode){ MessageBox.Show("Hello, World!"); } } I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

      1 Reply Last reply
      0
      • T t800t8

        I try to write a class that extends Form like that: public partial class BaseForm : Form { public BaseForm() { InitializeComponent(); } private void BaseForm_Load(object sender, System.EventArgs e) { MessageBox.Show("Hello, World!"); } } And then I write a class that extends class BaseForm public partial class MyForm : BaseForm { public MyForm() { InitializeComponent(); } } I rebuild project and open MyForm to design, it suddenly appears "Hello, World!" message box. I think it is a stupid feature in VS 2005 (I didn't check it in VS 2002, 2003 yet). How can I turn off this feature? http://t800t8.blogspot.com/2006/02/thc-thi-s-kin-load-khi-ang-design-form.html I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing -- modified at 19:58 Monday 20th February, 2006

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #4

        You think this is a stupid feature? How do you think controls work when you drop them on your form? There's nothing that magically renders them at design time without running the code that's in them. You MUST run code in the controls in order to see them on the form! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        T 1 Reply Last reply
        0
        • D Dave Kreskowiak

          You think this is a stupid feature? How do you think controls work when you drop them on your form? There's nothing that magically renders them at design time without running the code that's in them. You MUST run code in the controls in order to see them on the form! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          T Offline
          T Offline
          t800t8
          wrote on last edited by
          #5

          Render? Did you forget InitializeComponent() method in constructor? I just have some questions for you. + Do you like it shows a message like in my example at design time? + Do you like to get an error message and can not design your form when you only want to load the picture at runtime like this button1.Image = Image.FromFile(Constant.IMAGES_DIRECTORY_PATH + "Back.jpg"); ? These only some simple cases. If you like them, this stupid feature is for you! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

          J D 2 Replies Last reply
          0
          • T t800t8

            Render? Did you forget InitializeComponent() method in constructor? I just have some questions for you. + Do you like it shows a message like in my example at design time? + Do you like to get an error message and can not design your form when you only want to load the picture at runtime like this button1.Image = Image.FromFile(Constant.IMAGES_DIRECTORY_PATH + "Back.jpg"); ? These only some simple cases. If you like them, this stupid feature is for you! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #6

            This is exactly why the form exposes a DesignTime property as pointed out above

            1 Reply Last reply
            0
            • T t800t8

              Render? Did you forget InitializeComponent() method in constructor? I just have some questions for you. + Do you like it shows a message like in my example at design time? + Do you like to get an error message and can not design your form when you only want to load the picture at runtime like this button1.Image = Image.FromFile(Constant.IMAGES_DIRECTORY_PATH + "Back.jpg"); ? These only some simple cases. If you like them, this stupid feature is for you! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #7

              If you code your components correctly, this isn't a problem! Yes, I've written many of my own components, and yes, this "stupid feature" as you call it, is what made developing these components remarkably easy. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              T 1 Reply Last reply
              0
              • D Dave Kreskowiak

                If you code your components correctly, this isn't a problem! Yes, I've written many of my own components, and yes, this "stupid feature" as you call it, is what made developing these components remarkably easy. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                T Offline
                T Offline
                t800t8
                wrote on last edited by
                #8

                Can you show me the correct way to write a component? I want to see if it is correct or not. ;-) I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

                D 1 Reply Last reply
                0
                • T t800t8

                  Can you show me the correct way to write a component? I want to see if it is correct or not. ;-) I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #9

                  Funny! What do you think we've been trying to tell you!? Why is it so hard to accept that when you drop a component on a form, the code in it runs at design time?! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  T 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Funny! What do you think we've been trying to tell you!? Why is it so hard to accept that when you drop a component on a form, the code in it runs at design time?! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                    T Offline
                    T Offline
                    t800t8
                    wrote on last edited by
                    #10

                    I told you the reason why I think this feature is stupid. But you, nothing. I just want to give you an opportunity to defend your idea. And if you cannot defend it, I will keep my idea until I find it fail. Don't wasting my time! ;-) I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

                    D 1 Reply Last reply
                    0
                    • T t800t8

                      I told you the reason why I think this feature is stupid. But you, nothing. I just want to give you an opportunity to defend your idea. And if you cannot defend it, I will keep my idea until I find it fail. Don't wasting my time! ;-) I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #11

                      I don't have to! Just try and develop a control without that functionality! Of course, you can't turn it off, so, you'll just have to imagine that when you drop your control on a form to test it, nothing happens! You get a nice black hole where your control should paint itself. Why? Your rendering code doesn't run until you hit F5. You try changing a couple of properties to see if the rendering code is OK or see what the affects are, and nothing happens, until you hit F5. What a pain... It makes developing controls much easier to write and debug. If your skills can't handle that, well, ... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups