Hello there, I'm having problems with displaying graphics - I use a timer to update a panel every few seconds, and CPU load increases linearly with run time of my little program. It looks like this: //Timer that triggers my paint panel: public: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler( this, &Form1::panel1_Paint); panel1->Invalidate(); } //Paint panel public: System::Void panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { e->Graphics->DrawImage(test, 1, 1); } There's probably something wrong with the way I call up panel1_Paint -- but it's the only way I could figure out from the Visual C++ help file.. Oh and it would be great if anybody knew how to call up panel1_Paint and have it not delete all things I previously painted on it. Thanks in advance.
ruzu
Posts
-
Graphics causing high CPU load -
Newbie question - data storageYes, but I need non-static variables.. I've solved the problem anyway -- I initialized the variable twice, inside and outside of the function - so two instances of the variable, one with class scope and one with function scope were created. Yea, newbie mistake, so embarrassing :) Still, thanks a lot guys for the quick help.
-
Newbie question - data storageI have a plain Form class in which I have a function "timer1_Tick" which is executed on each tick event. In this function I use this line in order to call up a panel1_Paint function, which is also part of the Form class: [code] panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler( this, &Form1::panel1_Paint );[/code] And that's it. I just need a place where to initialize data. Obviously I can't initialize the data inside my timer1_Tick or inside the panel1_Paint function because it'd be initialized again and again. I tried initializing some values in the constructor Form1(): [code] int a; Bitmap^ bitmap; Form1() { InitializeComponent(); int a = 20; Bitmap^ bitmap = gcnew Bitmap("test.gif"); } [/code] But when I try to use them in my panel1_Paint function further down I see that they, while they have been initialized, they have not been assigned values yet. This is a variable scope problem I guess.
-
Newbie question - data storageHi folks, I'm creating a simple Visual C++ program which is supposed to display an animation: A timer event calls a panel_Paint() which writes the graphics on screen. My problem is that I cannot store data anywhere that will tell the panel_Paint() function at which frame of the animation it is so it knows which file to display - if I initialize a variable inside the function, it will be re-initialized next time it is called, and if I try to initialize a variable outside the function, I am told that I can only initialize static variables there. I'm new to Visual C++ and this kind of event-driven programming, maybe somebody can tell me where I can store data for my functions to use. Thanks in advance. -- modified at 20:59 Friday 20th January, 2006