|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Modal form stops code in another formI have code running in form 1 in a loop. The loop calls DoEvents frequently
so the UI is responsive. When I bring up a modal dialog by pressing a button on form 1, the code on form 1 stops running until the modal dialog is closed. Is there a way to keep the code in form 1 running even while the modal form is up? Thanks, Dave Dave wrote:
> I have code running in form 1 in a loop. The loop calls DoEvents One possible design would be to convert it to timer-driven, rather than loop-driven,> frequently so the UI is responsive. When I bring up a modal dialog > by pressing a button on form 1, the code on form 1 stops running > until the modal dialog is closed. Is there a way to keep the code in > form 1 running even while the modal form is up? iterations. On Wed, 19 Oct 2005 13:54:31 -0700, "Karl E. Peterson" <k***@mvps.org> Why have a Modal Form if you don't want it to behave like one ?wrote: >Dave wrote: >> I have code running in form 1 in a loop. The loop calls DoEvents >> frequently so the UI is responsive. When I bring up a modal dialog >> by pressing a button on form 1, the code on form 1 stops running >> until the modal dialog is closed. Is there a way to keep the code in >> form 1 running even while the modal form is up? First, modal forms behave differently between the IDE and the EXE version. I
know that MsgBox blocks Timer events in the IDE and not in the EXE version. I don't know about modal forms. Make a simple program that test these... > Is there a way to keep the code in form 1 running even while the modal Yes. If EXE mode does not behave differently than in IDE mode, then you > form > is up? could use a second Timer for this. Example: ' Show Form2 Timer2.Enabled = True Private Sub Timer2_Timer() Timer2.Enabled = False Form2.Show vbModal End Sub Show quoteHide quote "Dave" <D***@discussions.microsoft.com> wrote in message news:D497252C-9331-4D06-8866-610F6DB7630C@microsoft.com... >I have code running in form 1 in a loop. The loop calls DoEvents >frequently > so the UI is responsive. When I bring up a modal dialog by pressing a > button > on form 1, the code on form 1 stops running until the modal dialog is > closed. > Is there a way to keep the code in form 1 running even while the modal > form > is up? > > Thanks, > > Dave >
Show quote
Hide quote
"Dave" <D***@discussions.microsoft.com> wrote in message Are you sure you need to show it modal? If so, try the Timer that Karl news:D497252C-9331-4D06-8866-610F6DB7630C@microsoft.com... >I have code running in form 1 in a loop. The loop calls DoEvents >frequently > so the UI is responsive. When I bring up a modal dialog by pressing a > button > on form 1, the code on form 1 stops running until the modal dialog is > closed. > Is there a way to keep the code in form 1 running even while the modal > form > is up? > > Thanks, > > Dave mentioned. -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Please keep all discussions in the groups.. "Dave" <D***@discussions.microsoft.com> wrote in message Yes, but you have to get kind of tricky. First, there's no (simple) way to news:D497252C-9331-4D06-8866-610F6DB7630C@microsoft.com... >I have code running in form 1 in a loop. The loop calls DoEvents >frequently > so the UI is responsive. When I bring up a modal dialog by pressing a > button > on form 1, the code on form 1 stops running until the modal dialog is > closed. > Is there a way to keep the code in form 1 running even while the modal > form > is up? pick up RIGHT WHERE YOU LEFT OFF, in other words, if your code looked like this: *********************** Private Sub MyProc() Dim frmM As frmModal x = 1 x = x + 1 y = 2 [...] Set frmM = New frmModal frmM.Show vbModal x = x * 20 ************************ you're not going to be able to continue on at the x = x * 20 line without closing the modal form or calling the procedure again playing with flags and If statements. What you CAN do, however, is call ANOTHER procedure in the "main" form from the modal form. In other words, you could have this in frmModal: Private Sub Form_Load() Form1.RunSomeProcedure End Sub Now the modal form will be displayed and the code in the MyProc procedure will be suspended, but you can still execute code in Form1. Now, you're probably thinking, "But I set up a whole bunch of local variables in MyProc and I need to do something with them, and RunSomeProcedure won't know about them." Yeah, I know. What you're going to have to do is either make all those variables module-level, create a module-level structure with the needed info, or create a class which, again, you store in a module-level or higher-scoped variable. (Well, another option would be to pass all those variables to the modal form and have it turn around and pass them right back to Form1, but that's kinda icky in my opinion.) "Dave" <D***@discussions.microsoft.com> wrote in message I'd agree with Jerry and say "Why have a Modal Form if you don't want it to news:D497252C-9331-4D06-8866-610F6DB7630C@microsoft.com... > I have code running in form 1 in a loop. The loop calls DoEvents > frequently so the UI is responsive. When I bring up a modal dialog > by pressing a button on form 1, the code on form 1 stops running > until the modal dialog is closed. Is there a way to keep the code in > form 1 running even while the modal form is up? behave like one ?". However, if you just want the second Form to be "always on top of the main Form" while it is being shown (which it appears is what you actually do want) then simply show it specifying the main Form as its "owner": Form2.Show , Me Mike
Show quote
Hide quote
"Mike Williams" <M***@WhiskyAndCoke.com> wrote in message Let's say it's a progress form. During the long-running process you don't news:dj7trj$8fr$1@newsg2.svr.pol.co.uk... >> I have code running in form 1 in a loop. The loop calls DoEvents >> frequently so the UI is responsive. When I bring up a modal dialog >> by pressing a button on form 1, the code on form 1 stops running >> until the modal dialog is closed. Is there a way to keep the code in >> form 1 running even while the modal form is up? > > I'd agree with Jerry and say "Why have a Modal Form if you don't want it > to behave like one ?". However, if you just want the second Form to be > "always on top of the main Form" while it is being shown (which it appears > is what you actually do want) then simply show it specifying the main Form > as its "owner": > > Form2.Show , Me want any input on the main form, so you display the progress form modally. However, you want the long-running code to be house in the main form, not the progress form. Yes, you could simply disable the main form and show the progress form modelessly but on top, but that's not ideal. For example, If the user clicks on the app's button in the task bar, the main form will get focus (even though it's disabled), not the progress form. It doesn't look professional.
Show quote
Hide quote
"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message Show the progress bar form modally and have it call back to a procedure innews:u0oyMZX1FHA.2792@tk2msftngp13.phx.gbl > "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message > news:dj7trj$8fr$1@newsg2.svr.pol.co.uk... > >>> I have code running in form 1 in a loop. The loop calls DoEvents >>> frequently so the UI is responsive. When I bring up a modal dialog >>> by pressing a button on form 1, the code on form 1 stops running >>> until the modal dialog is closed. Is there a way to keep the code in >>> form 1 running even while the modal form is up? >> >> I'd agree with Jerry and say "Why have a Modal Form if you don't >> want it to behave like one ?". However, if you just want the second >> Form to be "always on top of the main Form" while it is being shown >> (which it appears is what you actually do want) then simply show it >> specifying the main Form as its "owner": >> >> Form2.Show , Me > > Let's say it's a progress form. During the long-running process you > don't want any input on the main form, so you display the progress > form modally. However, you want the long-running code to be house in > the main form, not the progress form. the main form or use a timer in the main form to kick off the process. It's not that the main form can't run code, just that the UI is unresponsive and the procedure doing the modal show is suspended. -- Reply to the group so all can participate VB.Net: "Fool me once..." "Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message I agree. But I wasn't sure exactly what the OP wanted (and I'm still not news:u0oyMZX1FHA.2792@tk2msftngp13.phx.gbl... > Yes, you could simply disable the main form and show the progress > form modelessly but on top, but that's not ideal. sure). There are of course lots of different ways of doing most things, and I'm sure there is an ideal way of doing exactly what the OP wants to do (if we knew what it was). > For example, If the user clicks on the app's button But it wouldn't be disabled (unless the OP specifically added code to do > in the task bar, the main form will get focus (even > though it's disabled), that). He has said that he has DoEvents in his main code loop (that he wants to keep running) and it might well be that he actually does want the user to be able to interact fully with both Forms while his code is running and at the same time for the secondary Form to be always on top of the main Form, in which case my solution would be fine, with a few subtle amendments to make it behave in a way that you would approve of, of course :-) Mike "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message Now that I look back at the original message I see the comment about the UI news:dj85ga$5rk$1@newsg4.svr.pol.co.uk... >> Yes, you could simply disable the main form and show the progress >> form modelessly but on top, but that's not ideal. > > I agree. But I wasn't sure exactly what the OP wanted (and I'm still not > sure). (of the main form??) being responsive and I'm with you: I'm not exactly sure what he wants. I was commenting on the "how do I make code in Form1 run while a modal form is displayed" aspect, which I guess is only a piece of his question.
Using shell command to map drive can't get redirect result to file
INSERT INTO how to split numeric part from letters in string Shrink Wrap Iterative GetObject get list of file names in a directory Is any device connected to COM1 port Division by Zero Error - Help Urgent InStr search counter Printing Blank lines for Top margin |
|||||||||||||||||||||||