Solved

Restrict Child form to MDIContainer area

Posted on 2004-08-11
16
507 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now