|
-
Jan 25th, 2007, 01:52 PM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] Wait+webbrowser
I have a button that does multiple things, but I want it to wait a certain amount of time in between doing different actions. how would I do so?
the first function is to navigate the webbrowser to a certain page, and the second function can only be done once the webpage is loaded, but the webpage only loads at the end...
Thnx
Phil.
-
Jan 25th, 2007, 01:57 PM
#2
Re: [2005] Wait+webbrowser
take the call to the second function out of the button click event, and move it to the document complete event. The document complete event fires when the webpage has fully loaded.
A side note to this is if you visit a page with frames, the DocumentComplete event fires for every frame that is loaded, and then a final time when everything is done. If the page does NOT have frames, DocumentComplete fires simply once when the page is loaded.
-
Jan 25th, 2007, 02:04 PM
#3
Thread Starter
Lively Member
Re: [2005] Wait+webbrowser
oh sweet, how do i write the documentcomplete event?
but the thing is that each event are in a For...Loop with a variable that is only used in the loop, so I can't move the code into an other function
-
Jan 25th, 2007, 02:18 PM
#4
Re: [2005] Wait+webbrowser
 Originally Posted by smart_phil_dude1
oh sweet, how do i write the documentcomplete event?
The same way you write code for a button click event. The documentcomplete event is just an event the control fires. Just go to the code view of the form, select the webbrowser control from the left combobox at the top of the code window, and select the documentcomplete event from the right dropdown and it will insert the needed prototype and you can code away.
 Originally Posted by smart_phil_dude1
but the thing is that each event are in a For...Loop with a variable that is only used in the loop, so I can't move the code into an other function
Then you need to go back and figure out another way to code it
-
Jan 25th, 2007, 04:40 PM
#5
Thread Starter
Lively Member
Re: [2005] Wait+webbrowser
Then you need to go back and figure out another way to code it
then is there a way to just make it wait a certain amount of time?
-
Jan 25th, 2007, 04:44 PM
#6
Re: [2005] Wait+webbrowser
you could try doing
system.threading.thread.sleep(x)
where x is the number of milliseconds to make it sleep.
However this sleeps the entire thread, and it may cause undesirable results.
You can try it though.
-
Jan 25th, 2007, 04:51 PM
#7
Thread Starter
Lively Member
Re: [2005] Wait+webbrowser
nope, the browser doesn't load.
-
Jan 25th, 2007, 04:53 PM
#8
Re: [2005] Wait+webbrowser
that is what I figured.
I don't know what you are trying to do in this loop of yours, so it is hard to make suggestions
-
Jan 25th, 2007, 05:00 PM
#9
Thread Starter
Lively Member
Re: [2005] Wait+webbrowser
well, what it does is load page number 1 that is in the first line of a textbox, then manipulate things on the webpage, then load page number 2 that is on the second line of the textbox, etc. until it has done each page on each line. and it also visits more than one webpage per line of the textbox, if you get what i mean...
is there a function that can make it just wait until the page has loaded, and then continue?
-
Jan 25th, 2007, 05:12 PM
#10
Re: [2005] Wait+webbrowser
if I were coding it... I would do this:
when the button is clicked, it navigates the webbrowser to the first line of the textbox.
when the documentcomplete event of the webbrowser fires, I would do whatever manipulation needs to be done. I would also check the URL of the webbrowser at this point to see if it has visited the last page it needs to for the given line in the textbox. When that happens, I would make a call to read the next line of the textbox and do it all over again until all lines were processed.
No loop needed, just a counter to keep track of what line in the textbox should get processed next.
-
Jan 25th, 2007, 05:19 PM
#11
Thread Starter
Lively Member
Re: [2005] Wait+webbrowser
ok i get what you mean, but i made it visit more than one page per line, and on each page it does different things... would it be possible of having more than one documentcomplete event, one for each page?
-
Jan 25th, 2007, 05:22 PM
#12
Re: [2005] Wait+webbrowser
the documentcomplete event fires whenever a given webpage has finished loading.
Checking the browsers current URL in the documentcomplete event (you can do this using the event args of the documentcomplete event (e.Url.ToString))
so by checking the current URL in the document complete event, you can do whatever manipulation needs to be done for the given page.
-
Jan 25th, 2007, 05:24 PM
#13
Thread Starter
Lively Member
Re: [2005] Wait+webbrowser
oh sweet thanks a lot now i know exactly what to do
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|