Question Make it wait

hemza

Member
Joined
Jan 15, 2009
Messages
6
Programming Experience
5-10
Hi,

How do I make my code wait until, for example, picture1.visible becomes false (I don't know how much time it will take until picture1.visible=false so I can't use sleep(...)). I need something like:

label1.text="..."
picture1.image=...
wait until picture1.visible=false
label1.text="picture1 is not visible"
...

Is it the same for waiting that a string str becomes empty i.e.
wait until str=""?

Thank you so much
 
PictureBoxes don't just magically become not visible. The Visible property of a PictureBox is not going to become False unless YOU set it to False. If YOU are setting it to False then you can simply set your Label's Text there.

Alternatively, you can handle the PictureBoxes VisibleChanged event and then set your Label's Text there. That way you're not specifically waiting for the property to change but rather you're just going about your business and then reacting to a notification that the property has changed. Think of it like this: you could stand in the kitchen and watch your mum make dinner and then eat when you see that it's ready, or you could intermittently stop what you're doing and go into the kitchen to check if dinner is ready and eat when you see that it is, or you could just go about your business and go out to eat when you hear your mum call "dinner's ready". The last option sounds like the most efficient, doesn't it? Your mum just call's out once and every member of the family can react to it, plus do other things in the mean time. That's a lot better than every member of the family standing in the kitchen until they see that dinner's ready.

Sorry for the slightly sexist example. ;)
 
Thank you very much but I was fearing you would answer this kind of answer.

Of course the picture box does not become invisible just by itself. The user will click on it and the picturebox_click will make it invisible. The problem is I can't put the code coming after the

wait until picturebox.visible=false

inside the picturebox_click because A LOT of subs need that wait event for the same picture box. I really need the following because it is the only way:

private sub mySub()
some code
wait until picturebox1.visible=false
rest of code
end sub

so I need exactly the following:

wait until picturebox1.visible=false
 
I've already provided the answer to your question. Handle the VisibleChanged event of your PictureBox. From that event handler you can call any methods you like. You cannot simply pause a method and wait for something to happen. If you have to change your design then so be it. You have to work within the rules of the system.
 
Back
Top