Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Windows 7 with Visual Basic 2010.

In my application I have a parent form named: Form1
that hosts two Child forms: Child1Form1 and ChildForm2

I have written the following code:

VB
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim DeskHeight As Integer : Dim DeskWidth As Integer
        DeskWidth = Screen.PrimaryScreen.WorkingArea.Width
        DeskHeight = Screen.PrimaryScreen.WorkingArea.Height
        Me.Show()
        Me.Size = New Size(DeskWidth, DeskHeight)
        Dim Location As Point : Location = New System.Drawing.Point(0, 0)
        Me.Location = Location
        Location = New System.Drawing.Point(0, 0)
        Me.Location = Location
        '--------------------------
        ChildForm2.MdiParent = Me
        Childform2.Location = New Point(175, 0)
        Childform2.Show()
        Dim ChildForm2Width, ChildForm2Height As Integer
        ChildForm2Width = DeskWidth - 175
        Childform2.Size = New Size(ChildForm2Width, DeskHeight)
        Location = New System.Drawing.Point(175, 0)
        Childform2.Location = Location
        ChildForm2.Text = "Child2"
        '-----------------------------
        ChildForm1.MdiParent = Me
        Childform1.Show()
        Childform1.Size = New Size(175, DeskHeight)
        Location = New System.Drawing.Point(0, 0)
        Childform1.Location = Location

    End Sub
End Class



My problem is how to make the two child forms fit inside Form1.
If Childform1 has a width of 175 as I set, then Childform2 width
should be:

Deskwidth-175

But this does'nt work. The working area for the child forms is smaller.
I have the same problem for the height of the child forms.
How can I calculate the working area (height -width) of the child forms so no scroll bars appeare ?
Posted
Updated 21-Jul-10 10:56am
v2

I don't follow you exactly, but it sounds like you want to fit the two child windows in the same space as the parent window, and you want to split the space between the two of them (though not necessarily in two halves). You might want to look into ClientRectangle, which will give you the area of a Window minus things like the title bar.
 
Share this answer
 
This is because the containersize (actual working space) of your parent
is smaller than the screen.workingarea you're using. Therefore you'll
need to get the containersize of the parent.

Check here
for the answer to a similar problem.
 
Share this answer
 
v2
Comments
MJK2010 22-Jul-10 8:47am    
Reason for my vote of 5
Solve the problem the best way
MJK2010 22-Jul-10 8:50am    
Thank you very much. I used the code in the recomended link and
the child forms are fitting inside the parent form correctly.
Again many thanks :)
You have to measure the content of the form, to know if it's going to fit in the area you provide, or if it will require scroll bars.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900