Solved

Restrict Child form to MDIContainer area

Posted on 2004-08-11
16
506 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

12 Experts available now in Live!

Get 1:1 Help Now