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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Closing a form - Tooltips

Closing a form - Tooltips

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 Posters 1 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.
  • G Offline
    G Offline
    Glen Harvy 0
    wrote on last edited by
    #1

    Hi, I have just added a tooltip component to a form and after I set a tooltip text, whenever I close the form I keep getting an "Object not set to an instance of an object" error message on closing the form. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); < --- "Object not set to an instance of object" error here } Here's the code that I use to close the form :- private void buttonFinished_Click(object sender, EventArgs e) { Dispose(); this.Close(); } This only occurs if I set the text for a tooltip. If I don't set any text no error is thrown. What gives? - Any ideas

    Glen Harvy

    F 1 Reply Last reply
    0
    • G Glen Harvy 0

      Hi, I have just added a tooltip component to a form and after I set a tooltip text, whenever I close the form I keep getting an "Object not set to an instance of an object" error message on closing the form. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); < --- "Object not set to an instance of object" error here } Here's the code that I use to close the form :- private void buttonFinished_Click(object sender, EventArgs e) { Dispose(); this.Close(); } This only occurs if I set the text for a tooltip. If I don't set any text no error is thrown. What gives? - Any ideas

      Glen Harvy

      F Offline
      F Offline
      Filip van der Meeren
      wrote on last edited by
      #2

      Just a small idea :laugh: : If you dispose your form when you press the Finishedbutton, then all the stuff in your form gets disposed :~ But after that you call the Close method. As far as i can see, the closemethod closes the form and releases all, by calling Dispose(bool). Try to compile/run your code without the dispose. I have never tried to call a dispose method inside the form that I want to close, I have always Disposed it outside of the form (many times I do not dispose it at all and just reset the form to reuse it a few moments later when the user wants to see it, what is very likely).

      Don't you also love the code?

      G 1 Reply Last reply
      0
      • F Filip van der Meeren

        Just a small idea :laugh: : If you dispose your form when you press the Finishedbutton, then all the stuff in your form gets disposed :~ But after that you call the Close method. As far as i can see, the closemethod closes the form and releases all, by calling Dispose(bool). Try to compile/run your code without the dispose. I have never tried to call a dispose method inside the form that I want to close, I have always Disposed it outside of the form (many times I do not dispose it at all and just reset the form to reuse it a few moments later when the user wants to see it, what is very likely).

        Don't you also love the code?

        G Offline
        G Offline
        Glen Harvy 0
        wrote on last edited by
        #3

        Thanks for making it all seem logical :-D . Getting rid of dispose does fix it of course. As an aside, when would one expicitly call dispose in a program?

        Glen Harvy

        F 1 Reply Last reply
        0
        • G Glen Harvy 0

          Thanks for making it all seem logical :-D . Getting rid of dispose does fix it of course. As an aside, when would one expicitly call dispose in a program?

          Glen Harvy

          F Offline
          F Offline
          Filip van der Meeren
          wrote on last edited by
          #4

          I know "my logic" together with my "PERFECT English" :sigh: makes my answer so easy to understand :-> I actually call the dispose method outside the form, when for an example you can't reset it to be reused or it does not have to be reused at all. Ofcourse you can always dump your forms when you no longer need them, it is easy and you don't have to think about your model (you never actually have to do that with .net X| ) But I have tested it, and in many cases I find it much more usefull to keep my forms around for just a bit longer then to just dump them and let the GC handle it (after a few years, when it finds the time to do so, on my machine never :rolleyes:).

          Don't you also love the code?

          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