|
-
May 16th, 2013, 04:24 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] MDI forms behaviour
If I run my application and open a child form, that form opens and anchors to the top left corner, underneath the application's menu bar, as it should do. Why then, if I close and then reopen it, does its position change - sometimes sitting on top of the application menu bar, concealing some of it, sometimes correctly sitting below the menu bar but moved down and across to the right? This applies to all my forms.
Each form has a
Code:
frmSetWork.MdiParent = Me
line in my frmMain_load sub but that is the only code I use (I think!) that relates to MDI. Have I missed something here?
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 04:34 AM
#2
Re: MDI forms behaviour
have you tried setting the child forms startposition property to manual?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 16th, 2013, 04:39 AM
#3
Thread Starter
Fanatic Member
Re: MDI forms behaviour
 Originally Posted by .paul.
have you tried setting the child forms startposition property to manual?
No, they are all set to WindowsDefaultLocation.
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 04:40 AM
#4
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 16th, 2013, 04:59 AM
#5
Thread Starter
Fanatic Member
Re: MDI forms behaviour
I've set this property to Manual but it's made no difference...
In any case I want my child forms to behave as child forms are meant to (unless I've misunderstood their default behaviour). Why would I need to set them as "Manual"?
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 05:13 AM
#6
Re: MDI forms behaviour
the defaultlocation of each new childform is slightly to the right + below the top of the previous form.
if you use the manual startposition you can specify in the child form_load event exactly where to put a new form
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 16th, 2013, 05:22 AM
#7
Thread Starter
Fanatic Member
Re: MDI forms behaviour
But some of my forms load *outside* the child form area (concealing the menu bar). And if I load, close and reopen the same form repeatedly, it's position seems pretty random - it doesn't systematically move down and right after each load. In other words the WindowsDefaultPosition property (presumably top left first and then moving as you described). OK, I could specify the position in the form load myself but surely that shouldn't be necessary?
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 05:26 AM
#8
Re: MDI forms behaviour
You have all the proof you need that that IS necessary.
I gave you the right solution to your problem.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 16th, 2013, 07:18 AM
#9
Thread Starter
Fanatic Member
Re: MDI forms behaviour
I don't think you have solved it. I have put
Code:
Me.Top = 0
Me.Left = 0
in the child form's load event and the form still displays unpredictably.
I was already aware that child forms are meant to cascade slightly each time they are opened but my first post describes that this isn't happening in my application. I'm not trying to overcome the cascading, I'm trying to achieve what the property WindowsDefaultLocation is meant to produce. Once again, I can't see why I should need the Manual property (plus some code) to do this.
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 07:38 AM
#10
Thread Starter
Fanatic Member
Re: MDI forms behaviour
Sorted!
I thought that having
Code:
frmSetWork.MdiParent = Me
in my frmMain load event would keep frmSetWork as a child form throughout the application. Apparently not. Putting
Code:
Me.MdiParent = frmMain
in the load event of the child form also seems to be necessary. But that's not what this link seems to suggest : http://msdn.microsoft.com/query/dev1...-.NETFramework
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 08:17 AM
#11
Re: MDI forms behaviour
Hmmm.... it would seem that you're setting the MDIParent of the default instance of the form... how are you creating and showing the child forms?
-tg
-
May 16th, 2013, 08:52 AM
#12
Thread Starter
Fanatic Member
Re: MDI forms behaviour
frmMain is the startup form.
The child forms are mostly opened by the user clicking on menu items on the frmMain menu bar which then issue the command frmWhatever.Show(). All of the child forms are listed in the load event of frmMain (frmWhatever.MdiParent = Me).
Hope this is what you were asking for!
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 09:09 AM
#13
Re: MDI forms behaviour
This is a reason that default instances get people in a lot of trouble. From what I can see, and agree with techgnome, you're starting default instances and not new instances of the forms. That's burning you in the butt right now. Can you show us/me the code you're using? Showing single lines is not really going to help out, sadly.
-
May 16th, 2013, 09:25 AM
#14
Thread Starter
Fanatic Member
Re: MDI forms behaviour
Here is a stripped down to absolute essentials (I hope!) look at what I'm doing :
Code:
Public Class frmMain
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmNewUser.MdiParent = Me
frmNewUser.Show()
End Sub
End Class
Public Class frmNewUser
Private Sub frmNewUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MdiParent = frmMain
End Sub
End Class
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 09:40 AM
#15
Re: MDI forms behaviour
Arg....
1) that code shouldn't be in the form load event of frmMain
2) that code shouldn't be in the form load event of the child form
3) you missed the most important piece of code... how in blue blazes are you showing the form? Specifically the menu click events? If that's where you're showing your forms, THAT's what we need to see... In THEORY it should be something like this:
Code:
Dim newUser as New frmNewUSer
newUser.MDIParent = Me
newUser.Show
That's it.. nothing complicated... create a new instance of the form... set the mdi parent, and show it... baddum-boom-badda-bing
"The child forms are mostly opened by the user clicking on menu items"
MOSTLY? what about the rest of the times? What ever... should be the same as the menu click events... in fact if that is the case and you are showing the form from different places, wrap it in a sub and call the sub from where you need to.
-tg
-
May 16th, 2013, 10:06 AM
#16
Thread Starter
Fanatic Member
Re: MDI forms behaviour
Presumably this means that the forms are destroyed each time they are closed?
Many thanks to techgnome, .paul., and formlesstree4.
Paul Orton
VB6
Visual Web Developer 2008 Express Edition
Microsoft Visual Basic 2012 Express
-
May 16th, 2013, 10:31 AM
#17
Re: MDI forms behaviour
It does look like you're using default instances still, which is not a good thing and will burn you so very much.
Also techgnome, I think it's "badda-bing, badda-boom"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|