[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Wait for a button click in a while loop

Yawen Chan

12/3/2002 8:45:00 AM

I have a while loop like this:

While (a != null)
{
// Wait for user to click on a button - how?

a.clickedLocation <- the location where the user clicked on the button

a <- a.next
}

How can I wait for a user click on the button in a while loop? Or the only
way I can get a mouse click is to do it through the Click event?

Thanks a lot.

Yawen


9 Answers

Nick Holmes

12/3/2002 9:29:00 AM

0

When the user clicks the button, an event will be will be raised. Why not
just react to that?

"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:#G#k#$pmCHA.1616@TK2MSFTNGP09...
> I have a while loop like this:
>
> While (a != null)
> {
> // Wait for user to click on a button - how?
>
> a.clickedLocation <- the location where the user clicked on the button
>
> a <- a.next
> }
>
> How can I wait for a user click on the button in a while loop? Or the
only
> way I can get a mouse click is to do it through the Click event?
>
> Thanks a lot.
>
> Yawen
>
>


Randy A. Ynchausti

12/3/2002 9:31:00 AM

0

Yawen Chan,

> I have a while loop like this:
>
> While (a != null)
> {
> // Wait for user to click on a button - how?
>
> a.clickedLocation <- the location where the user clicked on the button
>
> a <- a.next
> }
>
> How can I wait for a user click on the button in a while loop? Or the
only
> way I can get a mouse click is to do it through the Click event?

It is much easier to do this using an event handler.

Regards,

Randy


Yawen Chan

12/3/2002 9:49:00 AM

0

But in this case, I have a while loop. I want every item in an linked list
to be set to a value, so that when the user clicks on the button, the
current element is set. When the user clicks again, the next element is
set, and so on, until all the elements in the list is set.

I can use an event handler, only if I can wait for an event in the middle of
a function, so that when the event comes in and return, I can continue with
the function. Can I do that? Otherwise, I'll need to have some global
variables to keep track of which element I'm going to set in the linked
list.

What do you suggest?

Yawen

"Randy A. Ynchausti" <randy_ynchausti@msn.com> wrote in message
news:O8MsmZqmCHA.2308@TK2MSFTNGP10...
> Yawen Chan,
>
> > I have a while loop like this:
> >
> > While (a != null)
> > {
> > // Wait for user to click on a button - how?
> >
> > a.clickedLocation <- the location where the user clicked on the
button
> >
> > a <- a.next
> > }
> >
> > How can I wait for a user click on the button in a while loop? Or the
> only
> > way I can get a mouse click is to do it through the Click event?
>
> It is much easier to do this using an event handler.
>
> Regards,
>
> Randy
>
>


Nick Holmes

12/3/2002 10:28:00 AM

0

You just have to store state information in some private variables, and
figure out where you are up to each time the button is pressed. If you can
do it in a while loop, you can easily extend the idea to an event-driven
stateful implementation.

--
Nick Holmes
Coyote Software, GmbH.

"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:eJGxqjqmCHA.672@TK2MSFTNGP08...
> But in this case, I have a while loop. I want every item in an linked
list
> to be set to a value, so that when the user clicks on the button, the
> current element is set. When the user clicks again, the next element is
> set, and so on, until all the elements in the list is set.
>
> I can use an event handler, only if I can wait for an event in the middle
of
> a function, so that when the event comes in and return, I can continue
with
> the function. Can I do that? Otherwise, I'll need to have some global
> variables to keep track of which element I'm going to set in the linked
> list.
>
> What do you suggest?
>
> Yawen
>
> "Randy A. Ynchausti" <randy_ynchausti@msn.com> wrote in message
> news:O8MsmZqmCHA.2308@TK2MSFTNGP10...
> > Yawen Chan,
> >
> > > I have a while loop like this:
> > >
> > > While (a != null)
> > > {
> > > // Wait for user to click on a button - how?
> > >
> > > a.clickedLocation <- the location where the user clicked on the
> button
> > >
> > > a <- a.next
> > > }
> > >
> > > How can I wait for a user click on the button in a while loop? Or the
> > only
> > > way I can get a mouse click is to do it through the Click event?
> >
> > It is much easier to do this using an event handler.
> >
> > Regards,
> >
> > Randy
> >
> >
>
>


Cosmin Marin

12/3/2002 1:14:00 PM

0

Hi Yawen,

If this is what you really need, try to use wait handles. The technique is
to loop until a certain wait handle is signaled (set), while processing
events in the loop's body (Application.DoEvents). Attached is a small sample
with this.

regards,
cosmin

"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:#G#k#$pmCHA.1616@TK2MSFTNGP09...
> I have a while loop like this:
>
> While (a != null)
> {
> // Wait for user to click on a button - how?
>
> a.clickedLocation <- the location where the user clicked on the button
>
> a <- a.next
> }
>
> How can I wait for a user click on the button in a while loop? Or the
only
> way I can get a mouse click is to do it through the Click event?
>
> Thanks a lot.
>
> Yawen
>
>


begin 666 Form1.cs
M=7-I;F<@4WES=&5M.PT*=7-I;F<@4WES=&5M+D1R87=I;F<[#0IU<VEN9R!3
M>7-T96TN0V]L;&5C=&EO;G,[#0IU<VEN9R!3>7-T96TN0V]M<&]N96YT36]D
M96P[#0IU<VEN9R!3>7-T96TN5VEN9&]W<RY&;W)M<SL-"G5S:6YG(%-Y<W1E
M;2Y$871A.PT*=7-I;F<@4WES=&5M+E1H<F5A9&EN9SL-"@T*;F%M97-P86-E
M('1E<W1E=F5N=',-"GL-"@DO+R\@/'-U;6UA<GD^#0H)+R\O(%-U;6UA<GD@
M9&5S8W)I<'1I;VX@9F]R($9O<FTQ+@T*"2\O+R \+W-U;6UA<GD^#0H)<'5B
M;&EC(&-L87-S($9O<FTQ(#H@4WES=&5M+E=I;F1O=W,N1F]R;7,N1F]R;0T*
M"7L-"@D)<')I=F%T92!3>7-T96TN5VEN9&]W<RY&;W)M<RY"=71T;VX@8V%N
M8V5L.PT*"0EP<FEV871E(%-Y<W1E;2Y7:6YD;W=S+D9O<FUS+D)U='1O;B!S
M;VUE=&AI;F<[#0H)"7!R:79A=&4@4WES=&5M+E=I;F1O=W,N1F]R;7,N0G5T
M=&]N(%-T87)T.PT*"0EP<FEV871E(%-Y<W1E;2Y4:')E861I;F<N075T;U)E
M<V5T179E;G0@8R ](&YE=R!!=71O4F5S971%=F5N="AF86QS92DL#0H)"0ES
M(#T@;F5W($%U=&]297-E=$5V96YT*&9A;'-E*3L-"@D)+R\O(#QS=6UM87)Y
M/@T*"0DO+R\@4F5Q=6ER960@9&5S:6=N97(@=F%R:6%B;&4N#0H)"2\O+R \
M+W-U;6UA<GD^#0H)"7!R:79A=&4@4WES=&5M+D-O;7!O;F5N=$UO9&5L+D-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F5C="!S96YD97(L(%-Y<W1E;2Y%=F5N=$%R9W,@92D-"@D)
M>PT*"0D)4W1A<G0N16YA8FQE9" ](&9A;'-E.PT*"0D):6YT(')E=" ]("TQ
M.PT*"0D)+R\@;F]T92!T:&%T('1H92!T:6UE;W5T(&ES(#$L(&YO=" P.R!S
M971T:6YG(&ET('1O(# @=VEL;"!C875S90T*"0D)+R\@0U!5('5S86=E('1O
M(&=O('1O(#$P,"4-"@D)"7=H:6QE*%-Y<W1E;2Y4:')E861I;F<N5V%I=$AA
M;F1L92Y786ET5&EM96]U=" ]/2 H<F5T(#T-"@D)"0E!=71O4F5S971%=F5N
M="Y786ET06YY*&YE=R!786ET2&%N9&QE6UU[8RQS?2P@,2P@9F%L<V4I*2D-
M"@D)"7L-"@D)"0E!<'!L:6-A=&EO;BY$;T5V96YT<R@I.PT*"0D)?0T*"0D)
M365S<V%G94)O>"Y3:&]W*')E="Y4;U-T<FEN9R@I*3L-"@D)"5-T87)T+D5N
M86)L960@/2!T<G5E.PT*"0E]#0H-"@D)<')I=F%T92!V;VED(&-A;F-E;%]#
M;&EC:RAO8FIE8W0@<V5N9&5R+"!3>7-T96TN179E;G1!<F=S(&4I#0H)"7L-
M"@D)"6,N4V5T*"D[#0H)"7T-"@T*"0EP<FEV871E('9O:60@<V]M971H:6YG
M7T-L:6-K*&]B:F5C="!S96YD97(L(%-Y<W1E;2Y%=F5N=$%R9W,@92D-"@D)
<>PT*"0D)<RY3970H*3L-"@D)?0T*"7T-"GT-"@``
`
end

Nick Holmes

12/3/2002 1:29:00 PM

0

If you're going to do it this way, put the WaitHandles.WaitAny bit in
another thread, and ditch the bits with the timeouts and doevents!

But, I really do think that it is unnecessary to do it this way, and a bit
of state management can easily solve the problem.

--
Nick Holmes
Coyote Software, GmbH.

"Cosmin Marin" <cmarin@totalsoft.ro> wrote in message
news:uX7vnVsmCHA.2364@TK2MSFTNGP08...
> Hi Yawen,
>
> If this is what you really need, try to use wait handles. The technique is
> to loop until a certain wait handle is signaled (set), while processing
> events in the loop's body (Application.DoEvents). Attached is a small
sample
> with this.
>
> regards,
> cosmin
>
> "Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
> news:#G#k#$pmCHA.1616@TK2MSFTNGP09...
> > I have a while loop like this:
> >
> > While (a != null)
> > {
> > // Wait for user to click on a button - how?
> >
> > a.clickedLocation <- the location where the user clicked on the
button
> >
> > a <- a.next
> > }
> >
> > How can I wait for a user click on the button in a while loop? Or the
> only
> > way I can get a mouse click is to do it through the Click event?
> >
> > Thanks a lot.
> >
> > Yawen
> >
> >
>
>
>


Alan Pretre

12/3/2002 5:59:00 PM

0

"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:eJGxqjqmCHA.672@TK2MSFTNGP08...
> Otherwise, I'll need to have some global
> variables to keep track of which element I'm going to set in the linked
> list.
>
> What do you suggest?

This is correct, it is called a state machine, used to keep track of state
between clicks. That is the purpose of member variables, to maintain state.

-- Alan


Yawen Chan

12/4/2002 9:16:00 AM

0

Thanks everyone. It seems that the state machine is cleaner to implement.
I'll dig through these suggestions.

Yawen

"Nick Holmes" <nicknews.removeXs@coyXote-softXware.com> wrote in message
news:#PTbZfsmCHA.1008@tkmsftngp02...
> If you're going to do it this way, put the WaitHandles.WaitAny bit in
> another thread, and ditch the bits with the timeouts and doevents!
>
> But, I really do think that it is unnecessary to do it this way, and a bit
> of state management can easily solve the problem.
>
> --
> Nick Holmes
> Coyote Software, GmbH.
>
> "Cosmin Marin" <cmarin@totalsoft.ro> wrote in message
> news:uX7vnVsmCHA.2364@TK2MSFTNGP08...
> > Hi Yawen,
> >
> > If this is what you really need, try to use wait handles. The technique
is
> > to loop until a certain wait handle is signaled (set), while processing
> > events in the loop's body (Application.DoEvents). Attached is a small
> sample
> > with this.
> >
> > regards,
> > cosmin
> >
> > "Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
> > news:#G#k#$pmCHA.1616@TK2MSFTNGP09...
> > > I have a while loop like this:
> > >
> > > While (a != null)
> > > {
> > > // Wait for user to click on a button - how?
> > >
> > > a.clickedLocation <- the location where the user clicked on the
> button
> > >
> > > a <- a.next
> > > }
> > >
> > > How can I wait for a user click on the button in a while loop? Or the
> > only
> > > way I can get a mouse click is to do it through the Click event?
> > >
> > > Thanks a lot.
> > >
> > > Yawen
> > >
> > >
> >
> >
> >
>
>


Ravichandran J.V.

12/4/2002 2:46:00 PM

0

Surely, a solution can come up if you can clearly post what it is you
want by posting actual code.

with regards,

J.V.Ravichandran

*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!