Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to create dependent forms? (like MsgBoxes)
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Ashi_Mashi2




PostPosted: Fri Dec 30, 2005 8:39 pm   Post subject: 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..
Sponsor
Sponsor
Sponsor
sponsor
HazySmoke)345




PostPosted: Fri Dec 30, 2005 9:42 pm   Post subject: (No subject)

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




PostPosted: Sat Dec 31, 2005 11:51 am   Post subject: (No subject)

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




PostPosted: Sat Dec 31, 2005 2:59 pm   Post subject: (No subject)

Quote:
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:
code:
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? Very Happy
Ashi_Mashi2




PostPosted: Sat Dec 31, 2005 3:16 pm   Post subject: (No subject)

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




PostPosted: Sat Dec 31, 2005 3:35 pm   Post subject: (No subject)

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




PostPosted: Sat Dec 31, 2005 5:59 pm   Post subject: (No subject)

Then why not try this: In Form1, you put this:
code:
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




PostPosted: Sat Dec 31, 2005 8:44 pm   Post subject: 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:

VisualBASIC:
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:

VisualBASIC:
Form2.Show 1
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Sun Jan 01, 2006 11:22 am   Post subject: Re: How to create dependent forms? (like MsgBoxes)

Brightguy wrote:
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




PostPosted: Wed Jan 04, 2006 2:18 pm   Post subject: (No subject)

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




PostPosted: Wed Jan 04, 2006 8:10 pm   Post subject: (No subject)

Quote:
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... Confused
Brightguy




PostPosted: Wed Jan 04, 2006 10:46 pm   Post subject: Re: How to create dependent forms? (like MsgBoxes)

cool dude wrote:
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... Confused Besides, if I understood him correctly that what he wants to happen...

Ashi_Mashi2 wrote:
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




PostPosted: Thu Jan 05, 2006 1:17 pm   Post subject: (No subject)

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




PostPosted: Thu Jan 05, 2006 4:28 pm   Post subject: Re: How to create dependent forms? (like MsgBoxes)

Ashi_Mashi2 wrote:
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




PostPosted: Fri Jan 06, 2006 12:11 am   Post subject: (No subject)

yeah..so, if you combine the two ideas, you'll get what i want..Smile...thx...exactly like MsgBoxes..
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: