
-----------------------------------
Ashi_Mashi2
Fri Dec 30, 2005 8:39 pm

How to create dependent forms? (like MsgBoxes)
-----------------------------------
Hi, 

I'm not sure how expalin it..but, I want to create a form that is dependent on the parent, such that when the user clicks on the main window (either on the Taskbar or on the Window itself) my "child" form "blinks", and automatically changes focus from the parent form to the child...very much like MsgBoxes, where the user can only have access to one form...thanks..

-----------------------------------
HazySmoke)345
Fri Dec 30, 2005 9:42 pm


-----------------------------------
Since I'm not exactly sure what you're asking, I can only try to answer. If you're trying to make windows appear inside windows. Play with the property called MDIChild. Create a parent form, and a regular form. Make MDIChild "true" for the regular one and see what happens.

-----------------------------------
Ashi_Mashi2
Sat Dec 31, 2005 11:51 am


-----------------------------------
thanks for the replay...I tried the MDIChild option, but it gives the following error: No MDI Form available to load. 

Also, as an example, go to Tools-Internet Options-Settings (or any other window) and you see that once the "Settings" window appears, you can no longer select the "Internet Options" window unless you've closed the "Settings" window...i hope that helps...thanks agian :wink:

-----------------------------------
HazySmoke)345
Sat Dec 31, 2005 2:59 pm


-----------------------------------
Create a parent form, and a regular form.
You should create a MDI form first to make it work, but that's not the program that you want to make. Now that I see your point. This is what you do.

Let's say that you have Form1 and Form2. You want Form1 to freeze. So, this is what you type in Form1:
Private Sub Form_Load()
    Form1.Enabled = False
    Form2.Show
End Sub
If you disable the whole form, you can't do anything to that form now, can you?  :D

-----------------------------------
Ashi_Mashi2
Sat Dec 31, 2005 3:16 pm


-----------------------------------
thanks agian...
but, this is not quiet what i want...see, when i disable the form, it works fine when the window is 'active'..once you minimize it and want to use it again, it is still disabled but it does not automatically change it's 'focus' to the new form....i guess i need something to change the focus of one form to another...i tried the .setFocus method, doesnt work:S...

-----------------------------------
cool dude
Sat Dec 31, 2005 3:35 pm


-----------------------------------
hmm .setFocus should work thats wierd. wat do u mean by changing the focus? because .setFocus is usually to set the text box with a cursor.

-----------------------------------
HazySmoke)345
Sat Dec 31, 2005 5:59 pm


-----------------------------------
Then why not try this: In Form1, you put this:
Private Sub Form_Activate()
    Me.Enabled = False
    Form2.Show
End Sub

Private Sub Form_GotFocus()
    Form2.SetFocus
End Sub
So, whenever Form1 gets activated, it will lose focus again.

-----------------------------------
Brightguy
Sat Dec 31, 2005 8:44 pm

Re: How to create dependent forms? (like MsgBoxes)
-----------------------------------
The reason SetFocus doesn't work is because Form1 is still disabled.  To make the above code work properly, you want to add something like this in your active form:

Private Sub Form_Unload(Cancel As Integer)
    Form1.Enabled = True
End Sub
However, the easiest way to do this is to just use a modal form, like so:

Form2.Show 1

-----------------------------------
cool dude
Sun Jan 01, 2006 11:22 am

Re: How to create dependent forms? (like MsgBoxes)
-----------------------------------
The reason SetFocus doesn't work is because Form1 is still disabled.  

if u enable the first form than his first problem comes back, which is not to be able to click on the first form when the second form shows. the way HazySmoke)345 did it is absolutely right and it should work. if it doesn't please post the part of the code that doesn't work so we can help u better

-----------------------------------
Ashi_Mashi2
Wed Jan 04, 2006 2:18 pm


-----------------------------------
thanks a lot every1...

I used the "set focus" method and left all the forms enabled...
it works fine, but there is a problem with MsgBoxes:S...whenever I open a MsgBox in any of the child forms, it automatically switches to the parent form..places the msg box and then switches back to the child form, which is really annoying..any solutions?

-----------------------------------
HazySmoke)345
Wed Jan 04, 2006 8:10 pm


-----------------------------------
whenever I open a MsgBox in any of the child forms, it automatically switches to the parent form
What switches to the parent form? The focus? Well, when I tried to open a message box in Form2, the focus didn't return to Form1, in fact, the focus didn't return to any of the forms, it was at the MessageBox itself; Form2 is still on top of Form1. I don't see where your problem is...  :?

-----------------------------------
Brightguy
Wed Jan 04, 2006 10:46 pm

Re: How to create dependent forms? (like MsgBoxes)
-----------------------------------
if u enable the first form than his first problem comes back, which is not to be able to click on the first form when the second form shows.
I don't follow that... :? Besides, if I understood him correctly that what he wants to happen...

I used the "set focus" method and left all the forms enabled...
If you leave the forms enabled, they can still respond to events.  I thought you were describing modal forms, but maybe I misunderstood...

-----------------------------------
Ashi_Mashi2
Thu Jan 05, 2006 1:17 pm


-----------------------------------
thanks every1..but, actually, the only thing I was looking for was this:

form2.Show vbModeless, form1

this way, the second form is dependent (i.e. the child) of the first form..maybe I didnt explain it well...

anyways, thanks agian...

-----------------------------------
Brightguy
Thu Jan 05, 2006 4:28 pm

Re: How to create dependent forms? (like MsgBoxes)
-----------------------------------
thanks every1..but, actually, the only thing I was looking for was this:

form2.Show vbModeless, form1
Huh?  That's not what you described in your original message though... you said "where the user can only have access to one form".  So I'm confused why you would choose modeless over modal.

-----------------------------------
Ashi_Mashi2
Fri Jan 06, 2006 12:11 am


-----------------------------------
yeah..so, if you combine the two ideas, you'll get what i want..:)...thx...exactly like MsgBoxes..

-----------------------------------
Brightguy
Fri Jan 06, 2006 6:22 pm

Re: How to create dependent forms? (like MsgBoxes)
-----------------------------------
MsgBoxes are actually modal forms themselves... so I still don't understand why you wouldn't just use a modal form, unless you want some other kind of functionality you didn't mention.
