Solved

Problems positioning child window in a parent

Posted on 2011-02-26
2
285 Views
Last Modified: 2012-05-11
Hi there,

OK this one has me completely stumped. I have a parent container with which I can open a number of child windows within it.  All my other windows open at the top left corner.

Although I go through a bit of gymnastics to obtain the size of the window I have used the line:

Me.Location = New Point(0, 0)

Instead it displays down and to the right. If I close it and then open it again it displays further down and further right...

I have used the same process for the other child windows and they open correctly at the top left corner...

So, any ideas?

Simon


Public Sub setFormWidth() Implements accountINTERFACE.IfrmAccountDisplay.setFormWidth
        Try

            If Me.WindowState <> formWindowState.Maximized Then

                Dim totalWidth = 0
                Dim MaxWidth = 0
                Dim maxRows = 0
                Dim assetMaxWidth = 0
                Dim liabilityMaxWidth = 0
                Dim equityMaxWidth = 0
                Dim revenueMaxWidth = 0
                Dim expenseMaxWidth = 0

                Dim ToDo = 0
                Dim ds As System.Drawing.Graphics = CreateGraphics()

                maxRows = Math.Max(maxRows, dgvAssets.RowCount)
                maxRows = Math.Max(maxRows, dgvLiabilities.RowCount)
                maxRows = Math.Max(maxRows, dgvEquity.RowCount)
                maxRows = Math.Max(maxRows, dgvRevenue.RowCount)
                maxRows = Math.Max(maxRows, dgvExpenses.RowCount)

                Do While ToDo < maxRows

                    If ToDo < dgvAssets.RowCount Then

                        assetMaxWidth = Math.Max(assetMaxWidth, ds.MeasureString(dgvAssets.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    If ToDo < dgvLiabilities.RowCount Then

                        liabilityMaxWidth = Math.Max(liabilityMaxWidth, ds.MeasureString(dgvLiabilities.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    If ToDo < dgvEquity.RowCount Then

                        equityMaxWidth = Math.Max(equityMaxWidth, ds.MeasureString(dgvEquity.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    If ToDo < dgvRevenue.RowCount Then

                        revenueMaxWidth = Math.Max(revenueMaxWidth, ds.MeasureString(dgvRevenue.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    If ToDo < dgvExpenses.RowCount Then

                        expenseMaxWidth = Math.Max(expenseMaxWidth, ds.MeasureString(dgvExpenses.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    ToDo += 1

                Loop

                'Now determine the extra width needed if there are vertical scroll bars present.
                If (dgvAssets.DisplayRectangle.Width < dgvAssets.ClientRectangle.Width) Then

                    assetMaxWidth = assetMaxWidth + SystemInformation.VerticalScrollBarWidth

                ElseIf (dgvLiabilities.DisplayRectangle.Width < dgvLiabilities.ClientRectangle.Width) Then

                    liabilityMaxWidth = liabilityMaxWidth + SystemInformation.VerticalScrollBarWidth

                ElseIf (dgvEquity.DisplayRectangle.Width < dgvEquity.ClientRectangle.Width) Then

                    equityMaxWidth = equityMaxWidth + SystemInformation.VerticalScrollBarWidth

                ElseIf (dgvRevenue.DisplayRectangle.Width < dgvRevenue.ClientRectangle.Width) Then

                    revenueMaxWidth = revenueMaxWidth + SystemInformation.VerticalScrollBarWidth

                ElseIf (dgvExpenses.DisplayRectangle.Width < dgvExpenses.ClientRectangle.Width) Then

                    expenseMaxWidth = expenseMaxWidth + SystemInformation.VerticalScrollBarWidth

                End If

                If assetMaxWidth < 150 Then assetMaxWidth = 150
                If liabilityMaxWidth < 150 Then liabilityMaxWidth = 150
                If equityMaxWidth < 150 Then equityMaxWidth = 150
                If revenueMaxWidth < 150 Then revenueMaxWidth = 150
                If expenseMaxWidth < 150 Then expenseMaxWidth = 150


                assetMaxWidth = Fix(assetMaxWidth)
                liabilityMaxWidth = Fix(liabilityMaxWidth)
                equityMaxWidth = Fix(equityMaxWidth)
                revenueMaxWidth = Fix(revenueMaxWidth)
                expenseMaxWidth = Fix(expenseMaxWidth)

                assetSplitterDistance = assetMaxWidth + 44
                liabilitiesSplitterDistance = liabilityMaxWidth + 44
                equitySplitterDistance = equityMaxWidth + 44
                revenueSplitterDistance = revenueMaxWidth + 44
                expenseSplitterDistance = expenseMaxWidth + 44

                Me.Width = assetSplitterDistance + liabilitiesSplitterDistance + equitySplitterDistance + revenueSplitterDistance + expenseSplitterDistance + 20
                formWidth = Me.Width

                spcAssets.SplitterDistance = assetSplitterDistance
                spcLiabilities.SplitterDistance = liabilitiesSplitterDistance
                spcEquity.SplitterDistance = equitySplitterDistance
                spcRevExp.SplitterDistance = revenueSplitterDistance - 4

                Me.Location = New Point(0, 0)

                'Me.MaximumSize = New System.Drawing.Size(Me.Width, Me.MdiParent.DisplayRectangle.Height - 195)
                'Me.MinimumSize = New System.Drawing.Size(Me.Width, Me.MdiParent.DisplayRectangle.Height - 195)

                'Clean up the drawing surface
                ds.Dispose()

            End If

            loadedAgain = True

        Catch ex As Exception

            manageWindowsViewError("accountTASK", "frmAccountDisplay", "displayAccountsInDGV", ex)

        End Try

    End Sub

Open in new window

Screen-displays-down-and-to-the-.png
0
Comment
Question by:si2030
2 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 500 total points
ID: 34991206
_frmChildForm.MdiParent = Me.MdiParent
_frmChildForm.StartPosition = FormStartPosition.Manual
_frmChildForm.Location = System.Drawing.Point(0,0)
_frmChildForm.Show()
0
 

Author Closing Comment

by:si2030
ID: 34992725
This actually did work although I am not quite sure why I needed to include formstartpoint.manual to make this happen...

                Me.StartPosition = FormStartPosition.Manual
                Me.Location = New Point(0, 0)

Thanks :)
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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