Solved

Restrict Child form to MDIContainer area

Posted on 2004-08-11
16
511 Views
Last Modified: 2012-05-05
VB.Net / WinForms Application...

I have two forms: one is Parent, the other a Child Form.  At present, when the Child form is maximised, it fills the entire screen.  How do I restrict it to occupying only a certain area within the parent form?  I need the user to be able to see the menus etc on the parent form whilst in the Child form.

Thanks in advance...
0
Comment
Question by:Sigh_Man
  • 7
  • 3
  • 3
  • +1
16 Comments
 
LVL 25

Assisted Solution

by:RonaldBiemans
RonaldBiemans earned 20 total points
ID: 11772500
As far as I know a mdichild won't cover the menu on the parent. Could you post the code where you open the child form
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11772512
Unless you mean that the menu of the child overwrites the menu of the parent ?
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 11772586
(You'll notice that this code includes a check to stop the form being opened more than once at any given time...)

Here's my code for opening the Child Form...

Dim frmCaseDetailOpen As Boolean
        If frmCaseDetailOpen = False Then
            frmCaseDetailOpen = True
            'Create a new instance of frmCaseDetail...
            Dim NewMDIChild As New frmCaseDetail
            'Set the parent of the MDI child form...
            NewMDIChild.MdiParent = Me
            'Display the new form...
            NewMDIChild.Show()
        End If

        mnuSetupCaseDetail.Enabled = True
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 4

Accepted Solution

by:
srcalc earned 40 total points
ID: 11773165
This will keep the form at max 200 by 200 pixels and docked to the top-left of the parent form:

    Private Sub NewMDIChild_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
        If Me.Height > 200 Then
            Me.Height = 200
        End If
        If Me.Width > 200 Then
            Me.Width = 200
        End If
        Me.Left = Me.Parent.Left
        Me.Top = Me.Parent.Top
    End Sub
0
 
LVL 8

Assisted Solution

by:wguerram
wguerram earned 40 total points
ID: 11773178
Private Sub f_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles f.SizeChanged
        With f
            If .WindowState = FormWindowState.Maximized Then
                .WindowState = FormWindowState.Normal
                .Left = 0
                .Top = 0
                .Width = Me.Width - 12
                .Height = Me.Height - 60
            End If
        End With
    End Sub

This code will limit the form to the inner bounds of the parent form when maximized.

just declare the variable this way in the parent form

Dim WithEvents f As New Form2

Hope this help
0
 
LVL 4

Expert Comment

by:srcalc
ID: 11776403
Good point, wguerram. If you combine our too code samples it should work out great.
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 11790195
Good work.  Thanks.

Just to cap this question:  Is it generally better practise to use forms to keep certain parts of the program separate from others (ie contained within forms that have to be opened from menus, say) or is OK to use just one area "common" to all parts of the application?  (by that I mean hide certain objects and show other objects at RunTime).


Thanks
0
 
LVL 4

Expert Comment

by:srcalc
ID: 11790228
Using different forms makes it easier to stay organized if you have a lot of stuff to do in your app.
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 11791681
Thanks again!!   :D
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11792723
Just one question?

why did you accepted srcalc answer?

if you copy his code, it does not work when maximizing the window.

I just think it is not fair.

But are your points.
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 11801947
I went into the Split Points screen and allocated points based on the contributions of each.  Interestingly, the EE system seems to have arbitrarily selected the answer from srcalc to be labelled as the "Accepted Answer" despite the same allocation of points as yourself.

On the issue of the code not working:  I work long hours in a non-IT job.  Generally speaking, the only opportunity I get to program is at weekends, but much of my working week is spent contemplating certain solutions.  With EE, I find that the 'approaches' suggested by the Experts, to me, are as valuable as the code itself.  Given that I have now attained some degree of familiarity with VB.Net syntax, I will accept an answer if it provides me with sufficient information to solve my problem.  I hope that this explains the position.

On reflection, yes you offered slightly more and I probably should have awarded 30 points to you -- I hope you aren't too upset by this!
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 11801956
Sorry wguerram -- that should have read 60 points to you!!!!!   :D
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11809862
No, Problem i am just starting on this forum and i just want to help people with the knowledge i have gotten and i found pretty intersting, the idea on getting points for each answer you post.

It's fine.
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 13598418
RonaldBiemans,
I couldn't tempt you to have a crack at
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21358145.html
...could I?
It's a single form only - and I have posted all code there for it to run in a new project.  I cannot get the 12% interest to calculate correctly and this is now extremely urgent.
I shall post a further question with extra points if you fancy a pop at this question.
Thanks.
Sorry for the rude ask - but things are desperate!!    :-/
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13599153
I'll have a look :-)
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 13599156
Excellent - thanks!!   :D
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Datagridview column when exported to Excel changes vb.net 1 19
Calculate number of nights between two dates 5 53
Groupbox Control ? 2 17
Access Schema 6 25
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question