Solved

Problems positioning child window in a parent

Posted on 2011-02-26
2
270 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
Comment Utility
_frmChildForm.MdiParent = Me.MdiParent
_frmChildForm.StartPosition = FormStartPosition.Manual
_frmChildForm.Location = System.Drawing.Point(0,0)
_frmChildForm.Show()
0
 

Author Closing Comment

by:si2030
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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