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. Managed C++/CLI
  4. Can you suspend the OnPaint function?

Can you suspend the OnPaint function?

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++visual-studiohelpquestion
4 Posts 3 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.
  • B Offline
    B Offline
    BuckBrown
    wrote on last edited by
    #1

    Hi, I'm using Visual Studio 2005 C++/CLI. I have a Paint() function in my Form1 that has code to paint the screen in a block nested in an if statement. System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { if(myObject) { code to display screen } } This works fine when the constructor for myObject is called and an OpenFileDialog is used to read a file that can finish building the object. Since the Paint() function is called continuously, the code to display the screen is not executed when myObject is undefined, but when myObject is finished being instantiated then the display code executes. My problem is when I select "Cancel" in the OpenFileDialog I can stop building the myObject but the constructor completes (thus becoming NOT undefined) and the code to display the screen executes and tries to paint a bunch of undefined stuff and bombs the app. I've tried using a variable myObject->bValid in the above if statement but then the app bombs because the object reference was not set to an instance of an object. Is there a way to suspend the Paint() function so that I can do all of my preliminary stuff and then say "okay, start painting."? Thanks Buck

    C L 2 Replies Last reply
    0
    • B BuckBrown

      Hi, I'm using Visual Studio 2005 C++/CLI. I have a Paint() function in my Form1 that has code to paint the screen in a block nested in an if statement. System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { if(myObject) { code to display screen } } This works fine when the constructor for myObject is called and an OpenFileDialog is used to read a file that can finish building the object. Since the Paint() function is called continuously, the code to display the screen is not executed when myObject is undefined, but when myObject is finished being instantiated then the display code executes. My problem is when I select "Cancel" in the OpenFileDialog I can stop building the myObject but the constructor completes (thus becoming NOT undefined) and the code to display the screen executes and tries to paint a bunch of undefined stuff and bombs the app. I've tried using a variable myObject->bValid in the above if statement but then the app bombs because the object reference was not set to an instance of an object. Is there a way to suspend the Paint() function so that I can do all of my preliminary stuff and then say "okay, start painting."? Thanks Buck

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      No. You need to write code in onpaint that handles every possible case ( such as using a 'ready to paint' flag )

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • B BuckBrown

        Hi, I'm using Visual Studio 2005 C++/CLI. I have a Paint() function in my Form1 that has code to paint the screen in a block nested in an if statement. System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { if(myObject) { code to display screen } } This works fine when the constructor for myObject is called and an OpenFileDialog is used to read a file that can finish building the object. Since the Paint() function is called continuously, the code to display the screen is not executed when myObject is undefined, but when myObject is finished being instantiated then the display code executes. My problem is when I select "Cancel" in the OpenFileDialog I can stop building the myObject but the constructor completes (thus becoming NOT undefined) and the code to display the screen executes and tries to paint a bunch of undefined stuff and bombs the app. I've tried using a variable myObject->bValid in the above if statement but then the app bombs because the object reference was not set to an instance of an object. Is there a way to suspend the Paint() function so that I can do all of my preliminary stuff and then say "okay, start painting."? Thanks Buck

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi Buck, I would suggest you give your myObject a property Paintable or Valid, and set that appropriately in the constructor, and check it in your OnPaint. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        B 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi Buck, I would suggest you give your myObject a property Paintable or Valid, and set that appropriately in the constructor, and check it in your OnPaint. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Voting for dummies? No thanks. X|


          B Offline
          B Offline
          BuckBrown
          wrote on last edited by
          #4

          Thanks, I must b have a flaw in my flow. I tried using a flag to no avail. I will try again.

          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