Solved

Restrict Child form to MDIContainer area

Posted on 2004-08-11
16
509 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 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