Hi All,

I just created a simple displaying of photos in a CLR window form application just like a slideshow of photos. With the code below that is within a button_click, however the form will displayed only the last pic (picgen(3)) after all the sleep time of 4.5s. What should i do for it to display each photo just before each sleep() time?

picgen(1);
	Sleep(1000);
	picgen(0);
	Sleep(1500);
	picgen(1);
	Sleep(2000);
         picgen(3);

Recommended Answers

All 7 Replies

You need to force Form to repaint itself before each Sleep(). I'm not sure how to do that (I don't normall write CLR code) but here is a start.

You need to force Form to repaint itself before each Sleep(). I'm not sure how to do that (I don't normall write CLR code) but here is a start.

thanks for the fast reply :)

Sorry that i seem to be doing some paint event, actually when i use listbox to list 10 items through a loop, all of them will be listed at the end of the last item, i can't seem to get it to list item1 then item2 then item3 simultaneously till the last items.

That's because conrol is not returned back to Forms until after the function ends that adds the strings in the list box. It doesn't repaint the list box immediately after adding a string to prevent flicker and optimize performance. It would be exceedingly slow and awful looking if it had to repaint the form each time a string out of several hundred were added. I'm not well enough acquainted with Forms programming to know if you can add event hanlers to the list box or not.

What does picgen look like? Changing the background image of the picturebox (which is what it should be doing) should cause a refresh on the control, IIRC.

In fact if you had a uniform wait time in between you could use a timer control.

That's because conrol is not returned back to Forms until after the function ends that adds the strings in the list box. It doesn't repaint the list box immediately after adding a string to prevent flicker and optimize performance. It would be exceedingly slow and awful looking if it had to repaint the form each time a string out of several hundred were added. I'm not well enough acquainted with Forms programming to know if you can add event hanlers to the list box or not.

Very true, i will look into the event handler but currently i just make it into an animated gif.

Thanks

What does picgen look like? Changing the background image of the picturebox (which is what it should be doing) should cause a refresh on the control, IIRC.

In fact if you had a uniform wait time in between you could use a timer control.

Yup, changes the background image of picturebox, however even with the sleep time it only show the last pic. You have to wait for say 10s if that's total sleep time, sadly for only the last pic to show though.

Thanks

Thank you very much.

this->pictureBox1->Refresh();

before the sleep solved the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.