Reputation: 6152
I have a VB.NET MDI WinForms app. My users have been complaining about form creep (as they call it), this is where each time you open a specific form within the main MDI window it opens slightly below and to the right of the location it loaded previously - i.e. it starts in the top left of the window and works its way down to the bottom right.
I have to agree with them that this is extremely irritating, is there any way to prevent this? The code to load the forms is:
frmPurchaseInvoiceSelect.Show()
frmPurchaseInvoiceSelect.MdiParent = Me
I can address this somewhat by setting the forms start-up positions to 'Manual' but then they just open directly on top of each other in the top left of the screen.
Any other SO users come across this?
Upvotes: 2
Views: 3596
Reputation: 21
The following resolved it for me frmUser.StartPosition = FormStartPosition.Manual when reopened, it stopped 'creeping'
Upvotes: 2
Reputation: 6477
See my question and the resulting answer which might well help you with this problem. You can also look at my very verbose blog entry on the subject. My code is written in Delphi but you should be able to transfer the concepts to VB.
Upvotes: 1
Reputation: 136
MBoy,
MDI applications do not usually display windows centered although SDI applications may. In an MDI application with multiple windows open, a user generally wants to see the edge of each window (cascaded view) so that he/she can click on the desired window to bring it to the front. This can normally be done 2 ways. Know how many windows are open and their positions relative to the MDI frame. Open subsequent windows just below and to the right of the last window. This functionality is usually provided within the language or library used. The second way is to have a selection (menu or otherwise) to display the opened windows after the fact in the desired orientation (cascaded, tiled, or layered). As I mentioned before, if MDI display functionality is not provided automatically within the language/library, it will need to be coded manually. This can be done in a function which is called when each MDI window is opened but before it becomes visible.
Upvotes: 0
Reputation: 704
Try
frmPurchaseInvoiceSelect.StartPosition = FromStartPosition.CenterParent
to always start in the centre of the Mdi parent.
There are a few options but it depends on where you would like the form to start. I haven't tried it but:
frmPurchaseInvoiceSelect.Location = windowPoint
frmPurchaseInvoiceSelect.Size = windowSize
frmPurchaseInvoiceSelect.StartPosition = FormStartPosition.Manual
should start the form exactly where you want.
Upvotes: 4
Reputation: 136
Regardless of the language used, the cause is the same. When you open the first MDI window, the starting point is 0,0 relative to the MDI frame so it opens top left within the frame. If you close the window and then reopen it, the starting point is no longer 0,0 but some other value based on how you open windows (cascade, etc) Generally it will be slightly lower and to the right of the previous window which was closed. The problem exists because you or the tool are not checking to see if the window about to be opened is the only window instance within the frame. If the window is the only instance, open it at 0,0, otherwise open it at the appropriate position relative to the other windows.
This functionality would be usually handled by the MDI library you are using, or if not, you would code it manually. It only takes a few lines to code it manually so it should be trivial to implement.
Upvotes: 0