Can you suspend the OnPaint function?
-
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
-
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
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 )
-
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
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|
-
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|