Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,533 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,790 people online right now. Registration is fast and FREE... Join Now!




waiting for picturebox to load the image?

 
Reply to this topicStart new topic

waiting for picturebox to load the image?

chronoTrigger
18 Aug, 2008 - 04:57 PM
Post #1

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 43


My Contributions
I would like to know if there is a way that I can wait for the picturebox to show the image on screen before continuing to execute the next code?

thanks
User is offlineProfile CardPM
+Quote Post

Korupt
RE: Waiting For Picturebox To Load The Image?
18 Aug, 2008 - 05:22 PM
Post #2

D.I.C Head
Group Icon

Joined: 22 Jun, 2008
Posts: 58



Thanked: 1 times
Dream Kudos: 25
My Contributions
could you elaborate a little bit more i mean do you want the picture box to load before the form has shown:
csharp

private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Load();
}


or do you mean something like this:
csharp

//you code....

pictureBox1.Hide();

//more code...

pictureBox1.Show();

User is offlineProfile CardPM
+Quote Post

chronoTrigger
RE: Waiting For Picturebox To Load The Image?
18 Aug, 2008 - 08:20 PM
Post #3

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 43


My Contributions
Thank you for your reply. Sorry I didn't make it clear. When I said for the picturebox to load up, I meant the image itself has to be displayed inside the pictcurebox because I use the third party function to take the snapshot, but the function only works if there is a picture already exists in the picturebox. If there is no image showing, then the compiler generates error because the function that I use is trying to take a snapshot of the image that doesn't exist.

So the image has to show inside the picturebox on the screen, not the form although there is connection because for the picturebox to show, the form has to load up first that is what my code doing right now.

This post has been edited by chronoTrigger: 18 Aug, 2008 - 08:25 PM
User is offlineProfile CardPM
+Quote Post

Korupt
RE: Waiting For Picturebox To Load The Image?
19 Aug, 2008 - 11:30 AM
Post #4

D.I.C Head
Group Icon

Joined: 22 Jun, 2008
Posts: 58



Thanked: 1 times
Dream Kudos: 25
My Contributions
if you're trying to display the desktop picture in a picture box, I suggest you try this: http://www.codeguru.com/csharp/csharp/cs_g...icle.php/c6139/
User is offlineProfile CardPM
+Quote Post

chronoTrigger
RE: Waiting For Picturebox To Load The Image?
19 Aug, 2008 - 05:19 PM
Post #5

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 43


My Contributions
Just scanning through the code from your link already makes me dizzy because it's too complicated for me to follow.. But thanks though.
User is offlineProfile CardPM
+Quote Post

gbertoli3
RE: Waiting For Picturebox To Load The Image?
19 Aug, 2008 - 08:27 PM
Post #6

DIC at Heart + Code
Group Icon

Joined: 23 Jun, 2008
Posts: 1,046



Thanked: 17 times
Dream Kudos: 950
My Contributions
QUOTE(chronoTrigger @ 19 Aug, 2008 - 06:19 PM) *

Just scanning through the code from your link already makes me dizzy because it's too complicated for me to follow.. But thanks though.


How is it too hard to comprehend? It is all explained.
User is online!Profile CardPM
+Quote Post

djkitt
RE: Waiting For Picturebox To Load The Image?
20 Aug, 2008 - 07:14 AM
Post #7

D.I.C Head
**

Joined: 22 May, 2008
Posts: 128



Thanked: 13 times
My Contributions
QUOTE(chronoTrigger @ 18 Aug, 2008 - 07:57 PM) *

I would like to know if there is a way that I can wait for the picturebox to show the image on screen before continuing to execute the next code?

thanks


Just use the LoadCompleted event, like so:

CODE

        private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
                 // Call your snapshot routine in here,
        }


Hope this helps,


Kitt

User is offlineProfile CardPM
+Quote Post

chronoTrigger
RE: Waiting For Picturebox To Load The Image?
22 Aug, 2008 - 08:24 AM
Post #8

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 43


My Contributions
QUOTE(chronoTrigger @ 19 Aug, 2008 - 06:19 PM) *

Just scanning through the code from your link already makes me dizzy because it's too complicated for me to follow.. But thanks though.



There are just too many of Pinvoke which I'm still new to it, but thank you. I used the Timer event to display image and set the time interval. It works fine for now.

QUOTE(djkitt @ 20 Aug, 2008 - 08:14 AM) *

QUOTE(chronoTrigger @ 18 Aug, 2008 - 07:57 PM) *

I would like to know if there is a way that I can wait for the picturebox to show the image on screen before continuing to execute the next code?

thanks


Just use the LoadCompleted event, like so:

CODE

        private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
                 // Call your snapshot routine in here,
        }


Hope this helps,


Kitt


Using Timer for me is working fine. Although maybe LoadCompleted event can help me to determine whether the picture actually loaded without having to verify visually on screen because as it right now, the picture is loading what if in a different case the picture doesn't even load at all. I will check LoadCompleted, thanks.

This post has been edited by chronoTrigger: 22 Aug, 2008 - 08:25 AM
User is offlineProfile CardPM
+Quote Post

Allen.Brumley
RE: Waiting For Picturebox To Load The Image?
23 Aug, 2008 - 07:05 AM
Post #9

New D.I.C Head
*

Joined: 25 Jan, 2008
Posts: 16


My Contributions
QUOTE(chronoTrigger @ 18 Aug, 2008 - 07:57 PM) *

I would like to know if there is a way that I can wait for the picturebox to show the image on screen before continuing to execute the next code?

thanks


I presume you are just wanting the picture box to load before the next line of code executes?

In the picturebox properties you can also set WaitOnLoad to true which will cause the code to wait for the picture to load in the picture box before it executes the next line.
User is offlineProfile CardPM
+Quote Post

chronoTrigger
RE: Waiting For Picturebox To Load The Image?
23 Aug, 2008 - 08:13 PM
Post #10

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 43


My Contributions
Thanks Allen.
User is offlineProfile CardPM
+Quote Post

Allen.Brumley
RE: Waiting For Picturebox To Load The Image?
24 Aug, 2008 - 04:15 AM
Post #11

New D.I.C Head
*

Joined: 25 Jan, 2008
Posts: 16


My Contributions
QUOTE(chronoTrigger @ 23 Aug, 2008 - 11:13 PM) *

Thanks Allen.


Not a problem. You mentioned that you are not sure that the picture is loading all the time? Maybe a simple try/catch will help you monitor and fix it?

example:

CODE


try
{
picturebox1.image(.......
}
catch (Exception e)
{
Messagebox.show(.......
}


if the picturebox image failed to load you could avoid calling the routine that is giving you the exception or retry to load the image or ...............

lots of options. btw I had the same issue with the desktop program I wrote where the picturebox didn't load as fast as the program ran so it would error out on me. I fixed it by simply changing the WaitOnLoad to true and haven't had any problems since then.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 10:12PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month